/* 學生號碼旋轉輪盤 — 教室 16:9 桌機優先 */

:root {
  --bg: #070b18;
  --bg-2: #0e1730;
  --panel: rgba(18, 27, 51, 0.86);
  --panel-2: rgba(11, 18, 36, 0.9);
  --line: rgba(148, 178, 255, 0.16);
  --text: #eaf0ff;
  --muted: #93a4c8;
  --gold: #ffd24a;
  --gold-2: #ff9f1c;
  --accent: #4f8cff;
  --green: #35d07f;
  --red: #ff5d6c;
  --radius: 16px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1200px 700px at 18% -10%, rgba(79, 140, 255, 0.22), transparent 60%),
    radial-gradient(900px 600px at 100% 110%, rgba(255, 159, 28, 0.16), transparent 60%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 55%, #060a14 100%);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Heiti TC", "Segoe UI",
    system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body::after {
  /* 揭曉時的整頁閃光 */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(255, 210, 74, 0.45), transparent 55%);
  opacity: 0;
  transition: opacity 0.45s ease;
  z-index: 40;
}

body.winFlash::after {
  opacity: 1;
  transition: opacity 0.06s ease;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px 20px 16px;
  gap: 12px;
}

/* ------------------------------ 頂部列 ------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex: 0 0 auto;
}

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

.brandIcon {
  font-size: 34px;
  filter: drop-shadow(0 6px 14px rgba(255, 180, 40, 0.35));
}

.brandText h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.06em;
  background: linear-gradient(92deg, #fff 10%, var(--gold) 55%, var(--gold-2) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 12px;
  font-family: inherit;
}

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

.stat {
  min-width: 84px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat .k {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.14em;
}

.stat b {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------ 主舞台 ------------------------------ */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 396px;
  gap: 18px;
}

.wheelArea {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.wheelWrap {
  position: relative;
  aspect-ratio: 1 / 1;
  width: min(100%, calc(100vh - 300px));
  max-width: 100%;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.wheelWrap:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 6px;
  border-radius: 50%;
}

#wheel {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 24px 50px rgba(0, 0, 0, 0.55));
}

.fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pointer {
  position: absolute;
  top: -2px;
  left: 50%;
  width: 34px;
  height: 46px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #fff 0%, var(--gold) 40%, var(--gold-2) 100%);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
  z-index: 3;
}

.pointer::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #7a4a00;
  transform: translateX(-50%);
}

.hubBtn {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 21%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.75);
  background: radial-gradient(circle at 35% 30%, #3b4a72, #121a2f 70%);
  color: #fff;
  font-family: inherit;
  font-size: clamp(13px, 1.35vw, 20px);
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  z-index: 4;
  box-shadow: 0 0 0 6px rgba(255, 210, 74, 0.18), 0 10px 24px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.hubBtn:hover:not(:disabled) {
  background: radial-gradient(circle at 35% 30%, #4d61a0, #16203a 70%);
  box-shadow: 0 0 0 9px rgba(255, 210, 74, 0.26), 0 10px 28px rgba(0, 0, 0, 0.55);
}

.hubBtn:active:not(:disabled) {
  transform: translate(-50%, -50%) scale(0.95);
}

.hubBtn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.allDone {
  position: absolute;
  inset: auto 8% 12% 8%;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  border-radius: 14px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 93, 108, 0.95), rgba(160, 24, 44, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: var(--shadow);
  animation: popIn 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
}

.allDone strong {
  font-size: 20px;
}

.allDone span {
  font-size: 13px;
  opacity: 0.92;
}

.hidden {
  display: none !important;
}

/* 揭曉大字 */
.reveal {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
  min-height: 108px;
  padding: 4px 34px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 34px;
  color: var(--muted);
  letter-spacing: 0.08em;
  transition: color 0.3s ease;
}

.revealNumber {
  font-size: 92px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: #56637f;
  min-width: 2.4ch;
  text-align: center;
  transition: color 0.3s ease;
}

.reveal.pop {
  color: #fff;
  border-color: rgba(255, 210, 74, 0.4);
  background: linear-gradient(180deg, rgba(255, 210, 74, 0.12), rgba(255, 210, 74, 0));
  animation: revealBox 0.7s cubic-bezier(0.18, 1.5, 0.36, 1);
}

.reveal.pop .revealNumber {
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 210, 74, 0.75), 0 0 60px rgba(255, 159, 28, 0.45);
  animation: revealNumber 0.85s cubic-bezier(0.16, 1.6, 0.3, 1);
}

.reveal.spinning {
  color: var(--muted);
}

@keyframes revealBox {
  0% {
    transform: scale(0.94);
  }
  60% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes revealNumber {
  0% {
    transform: scale(0.25) rotate(-9deg);
    opacity: 0;
  }
  55% {
    transform: scale(1.28) rotate(2deg);
    opacity: 1;
  }
  75% {
    transform: scale(0.96) rotate(-1deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes popIn {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ------------------------------ 右側面板 ------------------------------ */

/* 設定內容可獨立捲動；底部操作列以 sticky 常駐可見（不使用 position: fixed） */
.panel {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 6px 8px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 178, 255, 0.35) transparent;
}

.panel::-webkit-scrollbar {
  width: 8px;
}

.panel::-webkit-scrollbar-thumb {
  background: rgba(148, 178, 255, 0.3);
  border-radius: 8px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 13px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(6px);
}

.card h2 {
  margin: 0 0 9px;
  font-size: 12.5px;
  letter-spacing: 0.14em;
  color: var(--gold);
  font-weight: 700;
}

.field + .field {
  margin-top: 10px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 5px;
}

.row {
  display: flex;
  gap: 8px;
}

input[type="number"],
input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 7px 11px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.22);
}

.hint {
  margin: 5px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: #7b8aad;
}

.btn {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #233257, #18233d);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.18);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.btn.primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-2) 100%);
  color: #2a1d00;
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 10px 26px rgba(255, 159, 28, 0.3);
}

.btn.big {
  width: 100%;
  font-size: 18px;
  padding: 13px 18px;
  letter-spacing: 0.1em;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.seg {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.seg.active {
  background: linear-gradient(180deg, rgba(79, 140, 255, 0.95), rgba(41, 92, 200, 0.95));
  color: #fff;
  box-shadow: 0 6px 16px rgba(79, 140, 255, 0.35);
}

/* 進度 */
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.progressBar {
  flex: 1 1 auto;
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}

.progressBar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green), var(--gold));
  transition: width 0.45s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.progressText {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.chipsHead {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 96px;
  overflow-y: auto;
}

.chip {
  min-width: 34px;
  text-align: center;
  padding: 4px 7px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(53, 208, 127, 0.16);
  border: 1px solid rgba(53, 208, 127, 0.45);
  color: #b8f5d3;
  animation: popIn 0.28s ease;
}

.chips .empty,
.history .empty {
  color: #6c7a99;
  font-size: 13px;
}

/* 最近紀錄 */
.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 9px;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
}

.history .ord {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10.5px;
  font-weight: 700;
  background: rgba(255, 210, 74, 0.18);
  color: var(--gold);
}

.history .num {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  min-width: 2.6ch;
}

.history .time {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.history li.newest {
  border-color: rgba(255, 210, 74, 0.5);
  animation: popIn 0.35s ease;
}

/* 開關與音量 */
.switchRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px !important;
  color: var(--text) !important;
  cursor: pointer;
  margin-bottom: 0 !important;
}

input.switch {
  appearance: none;
  width: 52px;
  height: 28px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
  flex: 0 0 auto;
}

input.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s cubic-bezier(0.2, 1.2, 0.4, 1);
}

input.switch:checked {
  background: linear-gradient(90deg, var(--green), #1fa864);
}

input.switch:checked::after {
  transform: translateX(24px);
}

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 8px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), rgba(255, 255, 255, 0.12));
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--gold-2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--gold-2);
}

.volValue {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* 主要操作列：常駐在面板底部，設定內容從它下方捲過（不使用 position: fixed） */
.actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: auto; /* 內容比面板短時，操作列仍貼齊面板底部 */
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0 2px;
  border-top: 1px solid var(--line);
  background: rgba(8, 12, 26, 0.95);
  box-shadow: 0 -10px 22px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(6px);
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 24px);
  background: rgba(12, 20, 38, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 20px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------ 螢幕適配 ------------------------------ */

@media (max-width: 1200px) {
  .stage {
    grid-template-columns: minmax(0, 1fr) 336px;
  }
  .revealNumber {
    font-size: 74px;
  }
}

/* 1366x768 的瀏覽器可視高度約 620~660px，仍要維持雙欄（操作列固定在面板底部），
   因此單欄模式的門檻下修到 560px，避免常見教室解析度誤切到單欄。 */
@media (max-width: 1000px), (max-height: 560px) {
  body {
    overflow: auto;
  }
  .app {
    height: auto;
    min-height: 100vh;
  }
  .stage {
    grid-template-columns: minmax(0, 1fr);
  }
  .wheelWrap {
    width: min(100%, 78vh);
  }
  .panel {
    overflow: visible;
  }
  /* 單欄模式：操作列移到最前面、緊接在輪盤下方，不必捲到頁面底部 */
  .actions {
    order: -1;
    position: static;
    margin-top: 0;
    padding: 0 0 10px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal.pop .revealNumber,
  .reveal.pop,
  .allDone,
  .chip,
  .history li.newest {
    animation-duration: 0.01ms !important;
  }
}
