:root {
  --bg1: #f5f2ed;
  --bg2: #ebe5dc;
  --fg: #f6eee6;
  --muted: #bba99a;
  --accent: #ffc65c;
  --card: rgba(30, 24, 20, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  color-scheme: dark;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--fg);
  background: radial-gradient(ellipse at 50% 40%, var(--bg1), var(--bg2) 75%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#stage canvas {
  display: block;
}

.labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.count {
  font-weight: 700;
  font-size: 15px;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  min-width: 26px;
  padding: 2px 7px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.count.store {
  font-size: 18px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--accent);
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 12px) 10px
    calc(env(safe-area-inset-left) + 12px);
  pointer-events: none;
}

#hud > * {
  pointer-events: auto;
}

.players {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
}

.player .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 28vw;
}

.player .score {
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.player.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 198, 92, 0.25);
}

.player.offline .name::after {
  content: " · away";
  color: var(--muted);
}

#turn {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

@media (max-width: 560px) {
  .players {
    flex-wrap: wrap;
  }
  #turn {
    order: 3;
    width: 100%;
    text-align: center;
  }
}

.icon-btn,
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  height: 38px;
  min-width: 38px;
  font-size: 16px;
  cursor: pointer;
}

.chip {
  padding: 0 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 8, 6, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}

.overlay[hidden],
#hud[hidden],
[hidden] {
  display: none !important;
}

.card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.sub {
  margin: 0;
  color: var(--muted);
}

.group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

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

.row > :first-child {
  flex: 1;
  min-width: 0;
}

input,
select,
button {
  font: inherit;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
}

input {
  user-select: text;
  -webkit-user-select: text;
}

#join-code {
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

button {
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}

button:hover {
  background: rgba(255, 255, 255, 0.13);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #2a1d0e;
  border-color: transparent;
}

button.primary:hover {
  background: #ffd486;
}

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

.rules {
  font-size: 14px;
  color: var(--muted);
}

.rules summary {
  cursor: pointer;
  color: var(--fg);
}

.rules ul {
  padding-left: 18px;
  margin: 8px 0 0;
  display: grid;
  gap: 4px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 20px);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
}

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

/* ---------- "Open in app" note (iOS Safari invite links) ---------- */

#app-note {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 8px 8px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 14px;
  color: var(--muted);
}

#app-note b {
  color: var(--accent);
  letter-spacing: 0.08em;
}

/* ---------- Force landscape on phones during a game ---------- */

#rotate {
  display: none;
}

@media (orientation: portrait) and (pointer: coarse) {
  body.in-game #rotate {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    text-align: center;
    background: radial-gradient(ellipse at 50% 40%, var(--bg1), var(--bg2) 75%);
    font-size: 17px;
  }
  .rotate-icon {
    font-size: 56px;
    animation: rotate-hint 2.4s ease-in-out infinite;
  }
}

@keyframes rotate-hint {
  0%, 25% { transform: rotate(0deg); }
  50%, 75% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* Landscape phones are short: tighten the menu so it fits without much scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  .overlay { place-items: start center; }
  .card { padding: 16px 20px; gap: 8px; }
  h1 { font-size: 26px; }
  input, select, button { padding: 8px 12px; }
}

/* Short landscape phones: compact top bar */
@media (orientation: landscape) and (max-height: 500px) {
  #hud { padding-top: calc(env(safe-area-inset-top) + 6px); gap: 6px; }
  .player { padding: 4px 10px; font-size: 14px; }
  .player .name { max-width: 22vw; }
  #turn { font-size: 13px; }
  .icon-btn, .chip { height: 32px; min-width: 32px; font-size: 14px; }
}

.setting {
  align-items: center;
}
.setting > span {
  flex: 1;
}

/* Realistic style: green felt table with an overhead-lamp vignette */
body.realistic {
  background: #17462a;
}
body.realistic #stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(0, 0, 0, 0.5) 100%);
}
