:root {
  --bg1: #fff6e9;
  --bg2: #ffe3c2;
  --card: #fffdf9;
  --ink: #4a3b2f;
  --ink-soft: #8b7767;
  --line: #f0e0cc;
  --accent: #f2994a;
  --accent-deep: #e8705f;
  --good: #7bb661;
  --shadow: 0 8px 24px rgba(196, 146, 92, 0.18);
  /* 动效 token：所有入场用 ease-out，位移用 ease-in-out */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --dur-press: 140ms;
  --dur-quick: 200ms;
  --dur-panel: 260ms;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg1) 0%, var(--bg2) 100%);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

input,
button,
textarea {
  font-family: inherit;
  font-size: 16px;
  color: inherit;
}

#app {
  min-height: 100dvh;
}

.view {
  display: none;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.view.active {
  display: block;
}

.hidden {
  display: none !important;
}

.hero {
  text-align: center;
  padding: 24px 0 18px;
}

.hero h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 4px;
  color: var(--accent-deep);
}

.hero p {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input[type='text'],
.field input[type='password'],
.field input:not([type]),
.field input[inputmode='numeric'] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffaf3;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
}

.field input[type='range'] {
  width: 100%;
}

.field.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field.switch > span {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
}

.field.switch input {
  width: 46px;
  height: 26px;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out), opacity var(--dur-quick) var(--ease-out);
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  box-shadow: 0 6px 16px rgba(232, 112, 95, 0.28);
}

.btn.ghost {
  background: #fff4e6;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.small {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 11px;
  width: auto;
}

.btn.danger {
  color: var(--accent-deep);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.link-btn {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 13px;
  text-decoration: underline;
}

.error {
  color: var(--accent-deep);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
}

.hint {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.topbar h2 {
  margin: 0;
  font-size: 17px;
}

.topbar .spacer {
  flex: 1;
}

.code-box {
  flex: 1;
  font-size: 13px;
  color: var(--ink-soft);
}

.code-box b {
  font-size: 20px;
  letter-spacing: 3px;
  color: var(--accent-deep);
}

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

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fff2e0;
  border: 2px solid #fff;
  box-shadow: 0 3px 10px rgba(196, 146, 92, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  overflow: hidden;
  flex: none;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar.small {
  width: 38px;
  height: 38px;
  font-size: 19px;
}

.avatar.off {
  filter: grayscale(1);
  opacity: 0.55;
}

.players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #fffaf3;
  border: 1px solid var(--line);
  transition: border-color var(--dur-quick) var(--ease-out),
    box-shadow var(--dur-quick) var(--ease-out), background-color var(--dur-quick) var(--ease-out);
}

.player-row.turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(242, 153, 74, 0.18);
}

.player-row .pname {
  flex: 1;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-row .ptag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 8px;
  background: #ffe9cf;
  color: var(--accent-deep);
}

.player-row .ptag.off {
  background: #eee6dc;
  color: var(--ink-soft);
}

.player-row .ptag.ready {
  background: #e6f3dd;
  color: #4f8a37;
}

.player-row .pscore {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: right;
  line-height: 1.4;
}

.player-row .pscore b {
  color: var(--accent-deep);
  font-size: 15px;
}

.seat-note {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.row .btn {
  flex: 1;
}

.big-score {
  text-align: center;
  margin: 6px 0 16px;
}

.big-score span {
  font-size: 46px;
  font-weight: 700;
  color: var(--accent-deep);
}

.big-score small {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 2px;
}

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

.chip {
  padding: 8px 14px;
  border-radius: 12px;
  background: #fff4e6;
  border: 1px solid var(--line);
  font-size: 14px;
  cursor: pointer;
}

.chip.on {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  border-color: transparent;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.swatch.on {
  outline: 2px solid var(--accent-deep);
  outline-offset: 1px;
}

.char-picker {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.char-picker canvas {
  background: #fff5e8;
  border-radius: 16px;
  border: 1px solid var(--line);
  flex: none;
}

.char-opts {
  flex: 1;
  min-width: 0;
}

.char-opts .chips {
  margin-bottom: 8px;
}

.char-opts .chip {
  padding: 6px 10px;
  font-size: 13px;
}

.char-opts .swatch {
  width: 24px;
  height: 24px;
}

/* ---------- 游戏 ---------- */

#view-game {
  position: fixed;
  inset: 0;
  padding: 0;
  display: none;
  flex-direction: column;
  background: linear-gradient(180deg, #fff3e2 0%, #ffe0bd 60%, #f7cfa2 100%);
}

#view-game.active {
  display: flex;
}

.hud {
  padding: calc(10px + env(safe-area-inset-top)) 14px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-score small {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
}

.hud-score b {
  font-size: 26px;
  color: var(--accent-deep);
  line-height: 1.1;
}

.hud-misses {
  flex: 1;
  font-size: 17px;
  letter-spacing: 2px;
}

.hud-turn {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-turn-name {
  max-width: 96px;
}

.hud-turn-name b {
  display: block;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-turn-name small {
  font-size: 11px;
  color: var(--ink-soft);
}

.timer {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-deep);
}

.timer.urgent {
  border-color: var(--accent-deep);
  animation: pulse 0.8s infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

#gameCanvas {
  flex: 1;
  width: 100%;
  display: block;
  touch-action: none;
}

.strip {
  display: flex;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  overflow-x: auto;
}

.strip .player-row {
  flex: none;
  min-width: 132px;
  padding: 6px 8px;
}

.strip .player-row .pname {
  font-size: 12px;
}

.strip .player-row .pscore {
  font-size: 11px;
}

.combo {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-deep);
  text-shadow: 0 2px 8px rgba(255, 255, 255, 0.9);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(6px);
  transition: opacity var(--dur-quick) var(--ease-out), transform var(--dur-quick) var(--ease-out);
}

.combo.pop {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  animation: comboPop 260ms var(--ease-out);
}

@keyframes comboPop {
  from {
    transform: translateX(-50%) scale(0.9);
  }
  to {
    transform: translateX(-50%) scale(1);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(74, 59, 47, 0.42);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  opacity: 0;
  transition: opacity 420ms var(--ease-out);
  pointer-events: none;
}

.overlay.show {
  opacity: 1;
}

.overlay-text {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 4px;
  transform: translateY(10px);
  opacity: 0;
  transition: transform 360ms var(--ease-out), opacity 360ms var(--ease-out);
}

.overlay-sub {
  margin-top: 8px;
  font-size: 15px;
  transform: translateY(10px);
  opacity: 0;
  transition: transform 360ms var(--ease-out) 60ms, opacity 360ms var(--ease-out) 60ms;
}

.overlay.show .overlay-text,
.overlay.show .overlay-sub {
  transform: translateY(0);
  opacity: 1;
}

.floating {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  z-index: 3;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(32px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(74, 59, 47, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  opacity: 0;
  transition: opacity var(--dur-quick) var(--ease-out), transform var(--dur-quick) var(--ease-out);
  pointer-events: none;
  z-index: 20;
  max-width: 80vw;
  text-align: center;
}

.toast.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 结算面板入场 ---------- */

#settlePanel.enter {
  animation: panelIn var(--dur-panel) var(--ease-out) both;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.player-row.row-in {
  animation: rowIn 300ms var(--ease-out) both;
}

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 减弱动效 ---------- */

@media (prefers-reduced-motion: reduce) {
  .timer.urgent {
    animation: none;
  }
  .toast,
  .combo,
  .combo.pop,
  .overlay,
  .overlay-text,
  .overlay-sub,
  #settlePanel.enter,
  .player-row.row-in {
    animation: none;
    transform: none;
  }
  .combo.pop {
    transform: translateX(-50%);
  }
  .toast {
    transform: translateX(-50%);
  }
  .toast.on {
    transform: translateX(-50%);
  }
  .combo,
  .overlay {
    transition-duration: 120ms;
  }
}
