:root {
  --ink: #1b1a17;
  --muted: #756e64;
  --paper: #f7f1e7;
  --paper-2: #fffaf0;
  --line: rgba(28, 26, 22, .13);
  --green: #1f8f75;
  --red: #db5350;
  --amber: #e1a845;
  --blue: #477ec6;
  --shadow: 0 18px 50px rgba(34, 28, 20, .14);
}

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

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 12%, rgba(225, 168, 69, .16), transparent 25%),
    radial-gradient(circle at 86% 84%, rgba(31, 143, 117, .13), transparent 27%),
    linear-gradient(145deg, #f8f3ea, #efe8de);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Inter", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.app {
  width: min(100vw, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  isolation: isolate;
}

.game-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.setup {
  min-height: 100dvh;
  padding: clamp(22px, 6vw, 40px);
  display: grid;
  align-content: center;
  gap: 22px;
}

.setup-mark {
  font-size: clamp(42px, 14vw, 80px);
  line-height: .9;
  font-weight: 950;
  letter-spacing: 0;
}

.setup-copy {
  margin: 0;
  max-width: 22rem;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.control-band {
  display: grid;
  gap: 14px;
}

.control-row {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  align-items: center;
}

.control-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .54);
  border: 1px solid var(--line);
}

.segmented button {
  min-height: 42px;
  border-radius: 6px;
  background: transparent;
  font-weight: 900;
  transition: background .2s ease, transform .2s ease, color .2s ease;
}

.segmented button.active {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 8px 18px rgba(26, 24, 20, .18);
}

.secret-panel {
  display: grid;
  gap: 13px;
  padding-top: 4px;
}

.secret-prompt {
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
}

.secret-digits,
.guess-digits {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 7px;
}

.digit-slot {
  height: clamp(42px, 11vw, 58px);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .7);
  border: 1px solid var(--line);
  box-shadow: inset 0 -5px 12px rgba(40, 32, 20, .04);
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 950;
}

.digit-slot.empty {
  color: rgba(27, 26, 23, .22);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
}

.keypad button,
.soft-button,
.primary-button,
.icon-button {
  min-height: 46px;
  border-radius: 8px;
  font-weight: 950;
  transition: transform .16s ease, background .2s ease, opacity .2s ease, box-shadow .2s ease;
}

.keypad button {
  background: rgba(255, 255, 255, .72);
  border: 1px solid var(--line);
}

.keypad button:disabled {
  opacity: .28;
  cursor: default;
}

.soft-button {
  background: rgba(255, 255, 255, .68);
  border: 1px solid var(--line);
}

.primary-button {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 13px 28px rgba(27, 26, 23, .18);
}

.primary-button:disabled {
  opacity: .34;
  cursor: default;
  box-shadow: none;
}

.setup-actions,
.guess-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.game {
  height: 100dvh;
  min-height: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 7px;
  overflow: hidden;
}

.opponents {
  min-height: 66px;
  display: grid;
  grid-template-columns: repeat(var(--opponents), minmax(0, 1fr));
  gap: 6px;
  align-items: start;
}

.player {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 3px;
  transition: filter .35s ease, opacity .35s ease, transform .35s ease;
}

.player.self {
  grid-template-columns: auto 1fr;
  justify-items: start;
  align-items: center;
  gap: 9px;
}

.avatar {
  width: clamp(44px, 12vw, 62px);
  aspect-ratio: 1;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  background-image: url("assets/avatars.png?v=20260617t");
  background-size: 300% 300%;
  background-position: calc(var(--x) * 50%) calc(var(--y) * 50%);
  border: 3px solid rgba(255, 255, 255, .82);
  box-shadow: 0 10px 28px rgba(40, 30, 20, .18);
}

.self .avatar {
  width: clamp(48px, 13vw, 66px);
}

.player.out {
  opacity: .48;
  filter: grayscale(1);
}

.player.speaking .avatar {
  animation: avatarSpeak .7s cubic-bezier(.2,.8,.2,1) both;
}

.player.out .avatar::after,
.player.lost .avatar::after {
  content: "x";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, .92);
  background: rgba(42, 35, 28, .46);
  font-size: 54px;
  font-weight: 950;
  line-height: 1;
}

.player-name {
  max-width: 100%;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history {
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  overflow: hidden;
}

.turn-ribbon {
  min-height: 24px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.log {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  padding: 2px 2px 10px;
  scrollbar-width: none;
}

.log::-webkit-scrollbar {
  display: none;
}

.empty-log {
  min-height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: rgba(117, 110, 100, .8);
  font-size: 15px;
  line-height: 1.5;
}

.entry {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .68);
  border: 1px solid rgba(28, 26, 22, .08);
  animation: slideIn .32s ease both;
}

.mini-avatar {
  width: 30px;
  aspect-ratio: 1;
  border-radius: 50%;
  background-image: url("assets/avatars.png?v=20260617t");
  background-size: 300% 300%;
  background-position: calc(var(--x) * 50%) calc(var(--y) * 50%);
}

.entry-guess {
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 950;
  letter-spacing: .08em;
}

.entry-result {
  min-width: 64px;
  color: #fff;
  background: var(--blue);
  border-radius: 7px;
  padding: 8px 9px;
  text-align: center;
  font-weight: 950;
}

.entry-result.hit {
  background: var(--green);
}

.bottom {
  display: grid;
  gap: 6px;
  overflow: hidden;
}

.bottom.hud-hidden {
  gap: 0;
}

.self-strip {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 50px;
}

.secret-chip {
  justify-self: start;
  color: var(--muted);
  font-weight: 950;
  letter-spacing: .12em;
  font-size: 13px;
}

.icon-button {
  width: 40px;
  min-height: 40px;
  background: rgba(255, 255, 255, .68);
  border: 1px solid var(--line);
}

.guess-pad {
  display: grid;
  gap: 6px;
  padding: 7px;
  border-radius: 10px;
  background: rgba(255, 250, 240, .72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transform-origin: bottom center;
  transition: opacity .2s ease, transform .22s ease;
}

.bottom.hud-hidden .guess-pad {
  display: none;
  opacity: 0;
  transform: translateY(8px) scale(.98);
}

.game .digit-slot {
  height: clamp(34px, 9vw, 44px);
  font-size: clamp(18px, 5vw, 24px);
}

.game .keypad button,
.game .soft-button,
.game .primary-button {
  min-height: 36px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.bubble {
  position: fixed;
  z-index: 30;
  min-width: 58px;
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, .93);
  box-shadow: 0 12px 28px rgba(36, 28, 20, .18);
  font-weight: 950;
  text-align: center;
  transform: translate(-50%, -50%) scale(.78);
  opacity: 0;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

.thought-bubble {
  position: fixed;
  z-index: 34;
  width: max-content;
  max-width: min(256px, calc(100vw - 28px));
  padding: 10px 13px;
  border-radius: 18px;
  color: rgba(27, 26, 23, .7);
  background: rgba(255, 255, 255, .78);
  border: 1px solid rgba(28, 26, 22, .1);
  box-shadow: 0 14px 38px rgba(36, 28, 20, .16);
  backdrop-filter: blur(16px);
  font-size: clamp(12px, 3.5vw, 14px);
  font-weight: 950;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -6px) scale(.92);
}

.thought-bubble::before,
.thought-bubble::after {
  content: "";
  position: absolute;
  left: 28px;
  top: -9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .74);
  border: 1px solid rgba(28, 26, 22, .08);
  box-shadow: 0 8px 20px rgba(36, 28, 20, .12);
}

.thought-bubble::before {
  width: 10px;
  height: 10px;
}

.thought-bubble::after {
  left: 43px;
  top: -18px;
  width: 16px;
  height: 16px;
}

.guess-bubble {
  position: fixed;
  z-index: 36;
  width: min(84vw, 360px);
  max-width: calc(100vw - 24px);
  padding: clamp(16px, 4vw, 24px) clamp(18px, 5vw, 30px);
  border-radius: 18px;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(27, 26, 23, .98), rgba(65, 55, 41, .96));
  box-shadow: 0 24px 74px rgba(27, 26, 23, .36);
  font-weight: 950;
  line-height: 1;
  text-align: center;
  letter-spacing: .1em;
  transform: translate(-50%, -50%) scale(.18);
  opacity: 0;
}

.guess-bubble::after {
  content: "";
  position: absolute;
  left: 18%;
  bottom: -10px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: inherit;
  transform: rotate(45deg);
}

.guess-bubble.digits-3 {
  font-size: clamp(48px, 17vw, 86px);
}

.guess-bubble.digits-4 {
  font-size: clamp(42px, 14vw, 74px);
}

.guess-bubble.digits-5 {
  font-size: clamp(34px, 11vw, 60px);
}

.final-flash {
  position: fixed;
  left: 50%;
  top: 48%;
  z-index: 40;
  min-width: 130px;
  padding: 18px 22px;
  border-radius: 12px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 22px 70px rgba(27, 26, 23, .32);
  text-align: center;
  font-size: clamp(34px, 13vw, 60px);
  font-weight: 950;
  transform: translate(-50%, -50%) scale(.72);
  opacity: 0;
}

.end-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(247, 241, 231, .72);
  backdrop-filter: blur(18px);
}

.end-copy {
  width: min(100%, 360px);
  display: grid;
  gap: 14px;
  text-align: center;
}

.end-face {
  justify-self: center;
  width: 126px;
  aspect-ratio: 1;
  border-radius: 50%;
  background-image: url("assets/avatars.png?v=20260617t");
  background-size: 300% 300%;
  background-position: calc(var(--x) * 50%) calc(var(--y) * 50%);
  box-shadow: var(--shadow);
  border: 4px solid rgba(255, 255, 255, .86);
}

.end-title {
  margin: 0;
  font-size: clamp(34px, 14vw, 64px);
  line-height: .94;
  font-weight: 950;
}

.end-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

@media (hover: hover) {
  button:hover:not(:disabled) {
    transform: translateY(-1px);
  }
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(.99);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes avatarSpeak {
  0% {
    transform: scale(1);
    box-shadow: 0 10px 28px rgba(40, 30, 20, .18), 0 0 0 0 rgba(27, 26, 23, .34);
  }
  36% {
    transform: scale(1.1);
    box-shadow: 0 12px 30px rgba(40, 30, 20, .2), 0 0 0 10px rgba(27, 26, 23, .1);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 10px 28px rgba(40, 30, 20, .18), 0 0 0 18px rgba(27, 26, 23, 0);
  }
}

@media (max-width: 390px) {
  .game {
    padding-left: 9px;
    padding-right: 9px;
  }

  .keypad {
    gap: 6px;
  }

  .guess-pad {
    padding: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}
