/* ── 設計 token ───────────────────────────────────────────── */
:root {
  --bg:            #fbfbfd;
  --surface:       #ffffff;
  --surface-sunk:  #f4f4f7;
  --border:        #e1e1e8;
  --border-strong: #c9c9d4;
  --text:          #17171c;
  --text-muted:    #63636e;
  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-fg:     #ffffff;
  --accent-wash:   #eeecff;
  --ok:            #0b7a4f;
  --danger:        #b3261e;
  --shadow:        0 1px 2px rgb(16 16 24 / .05), 0 8px 24px -12px rgb(16 16 24 / .18);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --dur: 180ms;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0d0d10;
    --surface:       #16161b;
    --surface-sunk:  #1d1d24;
    --border:        #2b2b34;
    --border-strong: #414150;
    --text:          #f3f3f6;
    --text-muted:    #a3a3af;
    --accent:        #8b83ff;
    --accent-hover:  #a29bff;
    --accent-fg:     #14141a;
    --accent-wash:   #211f3a;
    --ok:            #4ac68f;
    --danger:        #ff9a90;
    --shadow:        0 1px 2px rgb(0 0 0 / .4), 0 8px 24px -12px rgb(0 0 0 / .6);
  }
}

/* ── 基礎 ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* 有些元件自己指定了 display，會蓋掉 hidden 屬性的預設行為，這裡補回來 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang TC",
               "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }

:where(a, button, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 10;
  background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: var(--r-sm);
  border: 1px solid var(--border); text-decoration: none;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 8px; }

/* ── 版面 ─────────────────────────────────────────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-left)) 8px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 640;
  letter-spacing: -.01em;
}
.wordmark-mark { width: 22px; height: 22px; color: var(--accent); flex: none; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px max(20px, env(safe-area-inset-left))
           max(48px, env(safe-area-inset-bottom));
}

.title {
  margin: 0 0 6px;
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem);
  line-height: 1.25;
  letter-spacing: -.02em;
  font-weight: 680;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--text-muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* ── 密碼關卡 ─────────────────────────────────────────────── */
.gate { margin-top: 8vh; }
.gate-title { margin: 0 0 4px; font-size: 1.25rem; font-weight: 660; }
.gate-sub { margin: 0 0 20px; color: var(--text-muted); font-size: .9375rem; }
.gate-form { display: flex; flex-wrap: wrap; gap: 8px; }
.gate-form .input { flex: 1 1 200px; }

/* ── 表單元件 ─────────────────────────────────────────────── */
.input {
  min-height: 48px;
  width: 100%;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-weight: 580;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-hover); filter: brightness(.94); }

.btn-quiet {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-quiet:hover { background: var(--surface-sunk); }

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: .875rem;
  border-radius: var(--r-sm);
}

.ghost-btn {
  min-height: 44px;
  padding: 0 10px;
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: .875rem;
  cursor: pointer;
  transition: color var(--dur) var(--ease);
}
.ghost-btn:hover { color: var(--text); }

/* ── 拖放區 ───────────────────────────────────────────────── */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 220px;
  padding: 32px 24px;
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease),
              background-color var(--dur) var(--ease);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.is-over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-wash);
}
.dropzone-icon { width: 40px; height: 40px; color: var(--accent); flex: none; }
.dropzone-title { font-weight: 600; font-size: 1.0625rem; }
.dropzone-hint { color: var(--text-muted); font-size: .875rem; line-height: 1.5; }
.dropzone-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

/* ── 保存期限 ─────────────────────────────────────────────── */
.ttl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
.ttl-label { color: var(--text-muted); font-size: .9375rem; }

.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.seg {
  min-height: 40px;
  padding: 0 14px;
  background: none;
  border: 0;
  border-radius: 9px;
  color: var(--text-muted);
  font-size: .9375rem;
  font-weight: 560;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg:hover { color: var(--text); }
.seg[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgb(16 16 24 / .08);
}

/* ── 上傳中 ───────────────────────────────────────────────── */
.busy {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 220px;
  justify-content: center;
}
.busy-text { margin: 0; color: var(--text-muted); }
.spinner {
  width: 22px; height: 22px; flex: none;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 結果 ─────────────────────────────────────────────────── */
.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.result-check { width: 24px; height: 24px; color: var(--ok); flex: none; }
.result-title { margin: 0; font-size: 1.125rem; font-weight: 640; }

.link-row { display: flex; gap: 8px; }
.link-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--surface-sunk);
  font-size: .9375rem;
}
.link-row .btn { flex: none; }

.result-meta {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: .875rem;
}

.result-actions { display: flex; gap: 8px; margin-top: 20px; }
.result-actions .btn { flex: 1 1 0; }

/* ── 訊息 ─────────────────────────────────────────────────── */
.msg { margin: 16px 0 0; font-size: .9375rem; }
.msg-error { color: var(--danger); }

/* ── 最近分享 ─────────────────────────────────────────────── */
.history { margin-top: 40px; }
.history-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}
.history-title { margin: 0; font-size: .9375rem; font-weight: 620; color: var(--text-muted); }

.history-list { list-style: none; margin: 8px 0 0; padding: 0; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-main { flex: 1 1 auto; min-width: 0; }
.history-name {
  display: block;
  color: var(--text);
  font-size: .9375rem;
  text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-name:hover { text-decoration: underline; }
.history-sub { color: var(--text-muted); font-size: .8125rem; }
.history-badge {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 6px;
  font-size: .75rem;
  font-weight: 600;
  border-radius: 4px;
  background: var(--accent-wash);
  color: var(--accent);
}
.history-copy {
  flex: none;
  min-height: 44px; min-width: 60px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: .875rem;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.history-copy:hover { background: var(--surface-sunk); }
.history-note { margin: 16px 0 0; color: var(--text-muted); font-size: .8125rem; }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  font-size: .9375rem;
  box-shadow: var(--shadow);
  animation: toast-in var(--dur) var(--ease);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── 動效偏好 ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .spinner { animation: spin 1.2s linear infinite !important; }
}

/* ── 小螢幕 ───────────────────────────────────────────────── */
@media (max-width: 420px) {
  .card { padding: 20px; }
  .link-row { flex-wrap: wrap; }
  .link-row .btn { width: 100%; }
  .ttl-row { justify-content: space-between; }
}
