:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-muted: #efeae0;
  --text: #1c1b18;
  --text-muted: #656055;
  --border: #dfd8ca;
  --accent: #1c1b18;
  --accent-text: #ffffff;

  --cup-red: #e53935;
  --cup-yellow: #f6b915;
  --cup-green: #2e9e5b;
  --cup-blue: #1e78d6;
  --cup-black: #222326;

  --bell-gold: #eab308;
  --bell-gold-dark: #b45309;
  --win: #15803d;
  --lose: #b91c1c;

  --radius: 16px;
  --target-size: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

h1, h2, h3 {
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

[hidden] {
  display: none !important;
}

.app {
  min-height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(0.75rem, env(safe-area-inset-top, 0px))
    max(0.875rem, env(safe-area-inset-right, 0px))
    max(0.875rem, env(safe-area-inset-bottom, 0px))
    max(0.875rem, env(safe-area-inset-left, 0px));
  gap: 0.65rem;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: conic-gradient(var(--cup-red) 0 20%, var(--cup-yellow) 20% 40%, var(--cup-green) 40% 60%, var(--cup-blue) 60% 80%, var(--cup-black) 80% 100%);
}

.brand h1 {
  font-size: clamp(1.1rem, 1rem + 0.6vw, 1.35rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 0.4rem;
}

.icon-btn {
  min-width: var(--target-size);
  min-height: var(--target-size);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.94);
}

/* Screens */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen--center {
  justify-content: center;
  padding-block: 0.75rem;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.9rem;
  box-shadow: 0 6px 24px rgba(28, 27, 24, 0.06);
}

.hero-card h2 {
  font-size: clamp(1.3rem, 1.1rem + 1.1vw, 1.7rem);
  font-weight: 800;
}

.hero-card > p {
  color: var(--text-muted);
  line-height: 1.45;
  max-width: 34ch;
}

.hero-cups {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.mini-cup {
  width: 24px;
  height: 30px;
  border-radius: 4px 4px 8px 8px;
  background: var(--cup-color);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.mode-group {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.mode-group--3 {
  grid-template-columns: repeat(3, 1fr);
}

.mode-btn {
  min-height: 60px;
  padding: 0.6rem 0.4rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  text-align: center;
  font-size: 0.92rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.mode-btn span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mode-btn.is-selected {
  border-color: var(--accent);
  background: var(--surface-muted);
}

/* Friends Setup & Lobby */
.friends-setup {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.text-input {
  width: 100%;
  min-height: 46px;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
}

.text-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.friends-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.2rem;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  text-align: center;
  font-weight: 800;
}

.join-btn {
  width: auto !important;
  padding-inline: 1.35rem;
}

.inline-error {
  color: var(--lose);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

.room-code-display {
  font-size: 2.25rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  padding: 0.25rem 0.5rem;
}

.lobby-players-wrap {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lobby-players-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.lobby-player-list {
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.lobby-player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  font-size: 0.92rem;
}

.lobby-player-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.lobby-wait-text {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.difficulty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.diff-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-right: 0.2rem;
}

.pill-btn {
  min-height: 38px;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 600;
}

.pill-btn.is-selected {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.primary-btn,
.secondary-btn {
  width: 100%;
  min-height: 50px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.primary-btn {
  background: var(--accent);
  color: var(--accent-text);
}

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

.secondary-btn {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
}

.primary-btn:active:not(:disabled),
.secondary-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.best-time {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Active Game Layout */
.game-layout {
  justify-content: space-between;
  gap: 0.55rem;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.45rem 0.8rem;
  gap: 0.5rem;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.hud-stat--wide {
  flex: 1;
  min-width: 0;
}

.hud-stat--wide strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}

.hud-stat strong {
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.text-btn {
  min-height: var(--target-size);
  min-width: var(--target-size);
  padding: 0 0.65rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.875rem;
  border-radius: 8px;
}

.text-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.players-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.player-chip.is-me {
  border-color: var(--accent);
}

.player-chip.is-locked {
  opacity: 0.5;
  text-decoration: line-through;
}

/* Arena: Card + Player Tray */
.arena {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  min-height: 0;
}

@media (min-width: 480px) {
  .arena {
    grid-template-columns: 1fr 1fr;
  }
}

.card-panel,
.tray-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  min-height: 28px;
}

.orientation-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.bot-status {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.tray-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.target-card,
.player-tray {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.3rem;
  border-radius: 12px;
  background: var(--bg);
  min-width: 0;
}

.is-row {
  flex-direction: row;
}

.is-stack {
  flex-direction: column-reverse;
  gap: 0.22rem;
}

.slot-item {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  transition: transform 0.12s ease;
}

.is-row .slot-item {
  flex: 1;
  max-width: 48px;
  height: 44px;
}

.is-stack .slot-item {
  width: 64px;
  height: 22px;
  font-size: 0.7rem;
}

.slot-item--target {
  background: var(--cup-color);
  color: #ffffff;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

.slot-item--empty {
  border: 2px dashed var(--border);
  color: var(--text-muted);
  background: transparent;
}

.slot-item--next {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(28, 27, 24, 0.04);
}

.slot-item--filled {
  border: none;
  background: var(--cup-color);
  color: #ffffff;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
  cursor: pointer;
  animation: pop-in 0.12s ease-out;
}

@keyframes pop-in {
  from {
    transform: scale(0.75);
  }
  to {
    transform: scale(1);
  }
}

/* Feedback Banner */
.feedback-banner {
  text-align: center;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.92rem;
}

.feedback-banner.is-win {
  background: #dcfce7;
  color: var(--win);
}

.feedback-banner.is-lose {
  background: #fee2e2;
  color: var(--lose);
}

/* Controls: Bell + 5 Tap Cups */
.controls {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bell-btn {
  width: 100%;
  min-height: 54px;
  border-radius: 16px;
  border: 2px solid var(--bell-gold-dark);
  background: linear-gradient(180deg, #fde047 0%, var(--bell-gold) 100%);
  color: #422006;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  box-shadow: 0 5px 0 var(--bell-gold-dark);
  transition: transform 0.06s ease, box-shadow 0.06s ease, filter 0.15s ease;
}

.bell-btn:active:not(:disabled),
.bell-btn.is-rung {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--bell-gold-dark);
}

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

.bell-btn.is-ready {
  animation: bell-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes bell-pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.08);
  }
}

.bell-dome {
  width: 22px;
  height: 18px;
  border-radius: 14px 14px 4px 4px;
  background: #78350f;
  position: relative;
}

.bell-dome::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 4px;
  border-radius: 4px 4px 0 0;
  background: #422006;
}

.cup-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.42rem;
}

.cup-btn {
  min-height: 68px;
  padding: 0.4rem 0.2rem;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.32rem;
  box-shadow: 0 3px 0 var(--border);
  transition: transform 0.07s ease, opacity 0.12s ease, box-shadow 0.07s ease;
}

.cup-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--border);
}

.cup-btn:disabled {
  opacity: 0.25;
  box-shadow: none;
  cursor: default;
}

.cup-body {
  width: 34px;
  height: 36px;
  border-radius: 5px 5px 10px 10px;
  background: var(--cup-color);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22);
}

.cup-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
}

/* Color Tokens */
.c-red { --cup-color: var(--cup-red); }
.c-yellow { --cup-color: var(--cup-yellow); }
.c-green { --cup-color: var(--cup-green); }
.c-blue { --cup-color: var(--cup-blue); }
.c-black { --cup-color: var(--cup-black); }

.c-yellow.slot-item--target,
.c-yellow.slot-item--filled {
  color: #1c1b18;
}

/* End Screen */
.end-emoji {
  font-size: 3rem;
  line-height: 1;
}

.end-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Rules Dialog */
.rules-dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.rules-dialog::backdrop {
  background: rgba(28, 27, 24, 0.45);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.rules-list {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.rules-list strong {
  color: var(--text);
}

/* Game List & Desktop Keyboard Hints */
.brand-btn {
  border: none;
  background: transparent;
  padding: 0.25rem 0.35rem;
  border-radius: 10px;
}

.section-intro {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-block: 0.35rem 0.5rem;
}

.section-intro h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

.section-intro p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.game-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: 0 4px 16px rgba(28, 27, 24, 0.05);
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.game-card:hover {
  border-color: var(--accent);
}

.game-card:active {
  transform: scale(0.99);
}

.game-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-players {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.game-card-body {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.game-card-body h3 {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 0.2rem;
}

.game-card-body p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.game-dots {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.game-dot {
  width: 16px;
  height: 7px;
  border-radius: 3px;
}

.game-card-cta {
  align-self: flex-end;
  font-size: 0.85rem;
  font-weight: 800;
}

.setup-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.key-hint {
  display: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.38rem;
  border-radius: 5px;
  background: rgba(28, 27, 24, 0.12);
  color: inherit;
}

.key-hint--cup {
  position: absolute;
  top: 5px;
  right: 6px;
  font-size: 0.65rem;
  background: var(--surface-muted);
  color: var(--text-muted);
}

@media (hover: hover) and (pointer: fine) {
  .key-hint {
    display: inline-block;
  }

  .cup-btn {
    position: relative;
  }
}
