:root {
  --ink: #15213a;
  --muted: #64708a;
  --line: #dfe5f0;
  --paper: rgba(255, 255, 255, 0.92);
  --blue: #3456e8;
  --blue-dark: #2944bd;
  --green: #078a72;
  --purple: #7047d7;
  --shadow: 0 24px 70px rgba(44, 58, 107, 0.11);
}

* { box-sizing: border-box; }
html { color-scheme: light; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: #f4f7fc;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  z-index: -1;
  width: 36rem;
  height: 36rem;
  border-radius: 50%;
  filter: blur(12px);
  opacity: 0.72;
  pointer-events: none;
}

.ambient-one {
  top: -18rem;
  right: -8rem;
  background: radial-gradient(circle, rgba(121, 92, 246, 0.22), rgba(121, 92, 246, 0));
}

.ambient-two {
  bottom: -20rem;
  left: -12rem;
  background: radial-gradient(circle, rgba(31, 184, 157, 0.18), rgba(31, 184, 157, 0));
}

.shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 46px 0 44px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 36px;
  padding: 0 4px 28px;
}

.eyebrow-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.eyebrow,
.mode-badge,
.section-kicker {
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.eyebrow { color: var(--blue); }

.mode-badge {
  padding: 6px 11px;
  border: 1px solid #ccd4e8;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.76);
  letter-spacing: 0.04em;
}

.mode-badge::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: #99a3b9;
  content: "";
}

.mode-badge[data-mode="cloud"] { color: var(--green); border-color: #a9ded4; background: #effbf8; }
.mode-badge[data-mode="cloud"]::before { background: #0aa486; box-shadow: 0 0 0 4px rgba(10, 164, 134, 0.12); }
.mode-badge[data-mode="local"] { color: #a85b00; border-color: #f0d09b; background: #fff9ec; }
.mode-badge[data-mode="local"]::before { background: #e08a16; }

.mini-pill-btn {
  padding: 6px 12px;
  border: 1px solid #cfd8eb;
  border-radius: 999px;
  background: #fff;
  color: #344466;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: 150ms ease;
}
.mini-pill-btn:hover { border-color: var(--blue); color: var(--blue); background: #f2f5ff; }

.hero h1 {
  max-width: 720px;
  margin: 14px 0 12px;
  font-size: clamp(2.15rem, 5.4vw, 4.1rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.hero h1 span {
  color: transparent;
  background: linear-gradient(105deg, var(--blue), var(--purple) 55%, #b83280);
  -webkit-background-clip: text;
  background-clip: text;
}

.hero-copy > p {
  max-width: 660px;
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.75;
}

.stats { display: flex; gap: 12px; }

.stat {
  min-width: 118px;
  padding: 16px 18px;
  border: 1px solid rgba(213, 220, 235, 0.94);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 14px 34px rgba(58, 70, 116, 0.08);
  backdrop-filter: blur(14px);
}

.stat span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.76rem; }
.stat strong { color: var(--blue); font-size: 1.65rem; line-height: 1; }

.session-banner,
.composer,
.cloud-panel,
.ranking-panel,
.board-panel {
  border: 1px solid rgba(215, 222, 236, 0.94);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

/* 場次佈告欄橫幅 */
.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  padding: 20px 24px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(242, 246, 255, 0.94));
}

.session-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.session-code-pill,
.session-meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.session-code-pill {
  color: var(--blue-dark);
  background: #e6ecff;
  border: 1px solid #c8d6ff;
}

.session-meta-pill {
  color: #465470;
  background: #f3f6fc;
  border: 1px solid #dde4f2;
}

.session-info h2 {
  margin: 0 0 4px;
  font-size: 1.38rem;
  letter-spacing: -0.02em;
}

.session-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.session-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
}

.primary-small-btn {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--blue);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(52, 86, 232, 0.22);
  transition: 150ms ease;
}
.primary-small-btn:hover { background: var(--blue-dark); transform: translateY(-1px); }
.primary-small-btn:disabled { opacity: 0.6; cursor: wait; transform: none; }

/* 新增詞彙區 */
.composer { padding: 17px; }
.composer form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
.composer-inputs { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 10px; }
.word-field { position: relative; }

.composer input {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border: 2px solid transparent;
  border-radius: 15px;
  outline: 0;
  color: var(--ink);
  background: #f3f6fb;
  font-size: 0.98rem;
  transition: 160ms ease;
}
.word-field input { padding-right: 68px; }
.composer input:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 4px rgba(52, 86, 232, 0.1); }
.composer input::placeholder { color: #8d97ab; }

.char-count {
  position: absolute;
  top: 17px;
  right: 16px;
  color: #8b95aa;
  font-size: 0.78rem;
  pointer-events: none;
}

.composer button[type="submit"] {
  min-width: 138px;
  height: 54px;
  padding: 0 22px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(52, 86, 232, 0.24);
  transition: transform 130ms ease, background 160ms ease, opacity 160ms ease;
}
.composer button[type="submit"]:hover { background: var(--blue-dark); transform: translateY(-1px); }
.composer button[type="submit"]:disabled { opacity: 0.6; cursor: wait; transform: none; }

.composer-meta { display: flex; justify-content: space-between; gap: 20px; padding: 9px 4px 0; }
.composer-meta p { margin: 0; color: var(--muted); font-size: 0.78rem; }
#statusMessage.success { color: var(--green); }
#statusMessage.error { color: #c6324b; }

.cloud-panel,
.ranking-panel,
.board-panel {
  margin-top: 20px;
  padding: 24px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.panel-head h2 { margin: 2px 0 0; font-size: 1.4rem; letter-spacing: -0.02em; }
.section-kicker { margin: 0; color: var(--blue); font-size: 0.7rem; }

.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.ghost-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid #d8dfec;
  border-radius: 11px;
  color: #38445d;
  background: #f7f9fc;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: 150ms ease;
}
.ghost-button:hover { border-color: #b8c4de; background: #edf1f8; }

.cloud-stage {
  position: relative;
  width: 100%;
  height: clamp(360px, 48vw, 540px);
  max-height: 540px;
  overflow: hidden;
  border: 1px solid #e7ebf4;
  border-radius: 20px;
  background:
    radial-gradient(circle at center, rgba(52, 86, 232, 0.055) 0, rgba(52, 86, 232, 0) 52%),
    linear-gradient(#fafcff, #f7f9fd);
}

.cloud-stage::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.4;
  background-image: radial-gradient(#cfd7e8 0.7px, transparent 0.7px);
  background-size: 18px 18px;
  content: "";
}

#cloudCanvas { position: relative; z-index: 1; display: block; width: 100%; height: 100%; cursor: default; }

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}
.empty-orbit { display: grid; width: 76px; height: 76px; place-items: center; border: 1px dashed #aeb9d0; border-radius: 50%; }
.empty-orbit span { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 50%; color: var(--blue); background: #edf1ff; font-size: 1.5rem; }
.empty-state h3 { margin: 16px 0 4px; font-size: 1.1rem; }
.empty-state p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.hidden { display: none !important; }

.tooltip {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, calc(-100% - 12px));
  padding: 8px 11px;
  border-radius: 9px;
  color: #fff;
  background: #1d2941;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(21, 33, 58, 0.2);
}

.canvas-hint { margin: 10px 3px 0; color: var(--muted); font-size: 0.78rem; }

.panel-head.compact { margin-bottom: 15px; }
.panel-head.compact > span { color: var(--muted); font-size: 0.8rem; }
.word-chips { display: flex; flex-wrap: wrap; gap: 9px; min-height: 38px; }

.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 38px;
  padding: 7px 8px 7px 13px;
  border: 1px solid #dce2ee;
  border-radius: 999px;
  color: #35415a;
  background: #f8faff;
  cursor: pointer;
  transition: transform 130ms ease, border-color 150ms ease, background 150ms ease;
}
.word-chip:hover { transform: translateY(-1px); border-color: #adbce1; background: #eff3ff; }
.chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.chip-count { display: grid; min-width: 23px; height: 23px; padding: 0 5px; place-items: center; border-radius: 999px; color: var(--blue); background: #e4eaff; font-size: 0.72rem; font-weight: 900; }
.no-words { color: var(--muted); font-size: 0.9rem; }

/* 佈告欄與軌跡記錄 */
.tab-group {
  display: inline-flex;
  padding: 4px;
  border: 1px solid #dce3f0;
  border-radius: 12px;
  background: #f3f6fb;
  gap: 4px;
}

.tab-btn {
  padding: 7px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: 150ms ease;
}
.tab-btn.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 2px 8px rgba(32, 48, 92, 0.08);
}

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-input {
  width: min(340px, 100%);
  height: 38px;
  padding: 0 13px;
  border: 1px solid #d5ddec;
  border-radius: 10px;
  background: #f8faff;
  font-size: 0.86rem;
  outline: 0;
}
.search-input:focus { border-color: var(--blue); background: #fff; }

.toolbar-note { color: var(--muted); font-size: 0.8rem; }
.toggle-label { display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 600; color: #38445d; cursor: pointer; }

.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 14px;
}

.session-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid #dfe5f1;
  border-radius: 18px;
  background: #fafcff;
  transition: 150ms ease;
}
.session-card:hover { border-color: #b7c6eb; transform: translateY(-1px); }
.session-card.is-active {
  border-color: var(--blue);
  background: #f4f7ff;
  box-shadow: 0 8px 22px rgba(52, 86, 232, 0.1);
}

.session-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card-code {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--blue);
  background: #e8eeff;
  padding: 3px 8px;
  border-radius: 999px;
}
.card-date { font-size: 0.75rem; color: var(--muted); }
.session-card h3 { margin: 0; font-size: 1.02rem; line-height: 1.35; }
.card-meta { font-size: 0.8rem; color: var(--muted); }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid #e8edf6;
}
.card-stats { font-size: 0.76rem; color: #465470; font-weight: 600; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid #e4e9f4;
  border-radius: 16px;
}

.trail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  text-align: left;
}
.trail-table th {
  padding: 11px 13px;
  background: #f3f6fc;
  color: #42506d;
  font-weight: 800;
  white-space: nowrap;
  border-bottom: 1px solid #e0e6f2;
}
.trail-table td {
  padding: 10px 13px;
  border-bottom: 1px solid #eef2f8;
  color: var(--ink);
  vertical-align: middle;
}
.trail-table tr:last-child td { border-bottom: 0; }

.action-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}
.action-badge[data-action="建立場次"] { background: #ede9fe; color: #5b21b6; }
.action-badge[data-action="新增詞彙"] { background: #e0f2fe; color: #0369a1; }
.action-badge[data-action="投票加一"] { background: #dcfce7; color: #15803d; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(520px, 100%);
  padding: 24px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-head h3 { margin: 2px 0 0; font-size: 1.25rem; }
.icon-close {
  width: 34px;
  height: 34px;
  border: 1px solid #dce2ef;
  border-radius: 10px;
  background: #f8faff;
  cursor: pointer;
  font-weight: 700;
}

.modal-desc { margin: 0 0 14px; font-size: 0.85rem; color: var(--muted); line-height: 1.6; }
.modal-desc code { background: #f1f4fa; padding: 2px 5px; border-radius: 5px; color: var(--blue-dark); }

.modal-form { display: flex; flex-direction: column; gap: 13px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 0.82rem; font-weight: 700; color: #36435e; }
.req { color: #d94862; }
.form-row input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cfd8ea;
  border-radius: 11px;
  background: #f8faff;
  outline: 0;
}
.form-row input:focus { border-color: var(--blue); background: #fff; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1.25fr; gap: 12px; }
.code-input-group { display: flex; gap: 8px; }
.code-input-group input { flex: 1; min-width: 0; }

.form-error { margin: 0; font-size: 0.82rem; color: #c6324b; font-weight: 600; }
.form-hint { margin: 0; font-size: 0.82rem; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 60;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: #15213a;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
}

footer { display: flex; justify-content: space-between; gap: 20px; padding: 22px 5px 0; color: var(--muted); font-size: 0.76rem; }
footer p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 780px) {
  .shell { width: min(100% - 24px, 1180px); padding-top: 28px; }
  .hero { grid-template-columns: 1fr; gap: 20px; padding-bottom: 20px; }
  .stats { width: 100%; }
  .stat { flex: 1; min-width: 0; }
  .session-banner { flex-direction: column; align-items: flex-start; padding: 18px; }
  .composer form { grid-template-columns: 1fr; }
  .composer-inputs { grid-template-columns: 1fr; }
  .composer button[type="submit"] { width: 100%; }
  .composer-meta { flex-direction: column; gap: 4px; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .cloud-panel, .ranking-panel, .board-panel { padding: 17px; border-radius: 21px; }
  .cloud-stage { height: 400px; }
  .form-grid-2 { grid-template-columns: 1fr; }
  footer { flex-direction: column; gap: 4px; }
}
