:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: rgba(148, 163, 184, 0.18);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --fb-blue: #1877f2;
  --fb-blue-hover: #166fe5;
  --success: #10b981;
  --danger: #ef4444;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Noto Sans Thai', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 16px 64px;
  line-height: 1.6;
  position: relative;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  top: -120px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 400px;
  background: radial-gradient(circle, rgba(24, 119, 242, 0.22) 0%, rgba(11, 17, 32, 0) 70%);
  pointer-events: none;
  z-index: 0;
}

.container {
  width: 100%;
  max-width: 540px;
  position: relative;
  z-index: 1;
}

.header {
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--fb-blue);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 8px 24px rgba(24, 119, 242, 0.35);
}

.brand h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.hidden {
  display: none !important;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.9rem;
  font-weight: 600;
}

.required {
  color: var(--danger);
}

.optional {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.input-wrap {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="url"],
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus {
  border-color: var(--fb-blue);
  box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.2);
}

textarea {
  resize: vertical;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
}

button,
.btn-primary,
.btn-secondary {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.2s, opacity 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
}

button:active,
.btn-primary:active,
.btn-secondary:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--fb-blue);
  color: #fff;
  padding: 12px 18px;
}

.btn-primary:hover {
  background: var(--fb-blue-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  font-size: 0.88rem;
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.14);
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0 14px;
  flex-shrink: 0;
  font-size: 0.85rem;
}

.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.14);
}

.btn-text {
  background: transparent;
  color: var(--fb-blue);
  font-size: 0.88rem;
  padding: 4px 6px;
  text-decoration: none;
}

.btn-text:hover {
  text-decoration: underline;
}

.btn-full {
  width: 100%;
}

.btn-lg {
  padding: 14px 20px;
  font-size: 1.05rem;
}

/* Result Box */
.result-box {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.result-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.share-url-row {
  display: flex;
  gap: 8px;
}

.share-url-row input {
  font-size: 0.88rem;
  color: #93c5fd;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-actions > * {
  flex: 1 1 auto;
}

.qr-container {
  margin-top: 8px;
  padding: 18px;
  background: var(--surface-2);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#qr-code {
  background: #fff;
  padding: 12px;
  border-radius: 10px;
}

.qr-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* History */
.history-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history-header h2 {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-meta {
  min-width: 0;
  flex: 1;
}

.history-title {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-url {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Viewer Mode */
.viewer-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(24, 119, 242, 0.14);
  color: #60a5fa;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.viewer-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fb-blue);
}

.viewer-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 8px;
  word-break: break-word;
}

.viewer-note {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.destination-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  word-break: break-all;
}

.dest-label {
  color: var(--text-muted);
  margin-right: 6px;
}

.dest-url {
  color: #93c5fd;
}

.viewer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.embed-wrapper {
  margin-top: 18px;
  text-align: center;
}

.embed-frame-box {
  margin-top: 12px;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
}

.embed-frame-box iframe {
  width: 100%;
  border: none;
  min-height: 360px;
  display: block;
}

.invalid-box {
  text-align: center;
  padding: 20px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.invalid-box p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.viewer-footer {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 100;
}
