:root {
  color-scheme: light;
  --paper: #f7edda;
  --surface: #fff7e7;
  --ink: #142d23;
  --muted: #40574b;
  --line: #9d691f;
  --coral: #a93622;
  --coral-hover: #882916;
  --on-coral: #fff9ee;
  --grain: #6944140b;
  --shadow: #412a1c32;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --gutter: clamp(10px, 3vw, 24px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #112a21;
  --surface: #19362b;
  --ink: #fff4db;
  --muted: #d9debd;
  --line: #e3b35a;
  --coral: #ee7656;
  --coral-hover: #ff9a7e;
  --on-coral: #2e170f;
  --grain: #fff5d30d;
  --shadow: #080d0970;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 1px 2px, var(--grain) 0.6px, transparent 0.8px),
    radial-gradient(circle at 4px 5px, var(--grain) 0.5px, transparent 0.7px);
  background-size: 7px 9px, 11px 13px;
  color: var(--ink);
  font: 500 1rem/1.35 system-ui, sans-serif;
}

@media (display-mode: standalone) {
  html {
    touch-action: pan-x pan-y;
  }
}

.version-watermark {
  position: fixed;
  right: calc(8px + var(--safe-right));
  bottom: calc(2px + var(--safe-bottom));
  z-index: 1;
  color: var(--muted);
  font-size: .65rem;
  opacity: .7;
  pointer-events: none;
}

[hidden] { display: none !important; }

.install-guide {
  width: 100%;
  max-width: 36rem;
  margin-inline: auto;
  padding-block: calc(1.5rem + var(--safe-top)) calc(1.5rem + var(--safe-bottom));
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
  line-height: 1.55;
}

.install-guide h1 { margin-block-start: 0; }
.install-guide ol { padding-inline-start: 1.5em; }
.install-guide li + li { margin-block-start: .4em; }
.install-guide a { color: inherit; }
.install-guide a:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

.topbar,
.main {
  width: 100%;
  max-width: 600px;
  margin-inline: auto;
  padding-left: calc(var(--gutter) + var(--safe-left));
  padding-right: calc(var(--gutter) + var(--safe-right));
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-block: calc(6px + var(--safe-top)) 4px;
}

.topbar::after {
  content: "";
  flex-basis: 100%;
  height: 1px;
  background: var(--line);
}

h1 {
  margin: 0;
  font: 900 clamp(1.6rem, 6vw, 2.15rem)/1 Georgia, "Times New Roman", serif;
  letter-spacing: -.045em;
  text-transform: uppercase;
}

#remaining-label {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}

.btn:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 2px;
}

.settings-screen {
  width: 100%;
  max-width: 600px;
  margin-inline: auto;
  padding-block: calc(1rem + var(--safe-top)) calc(1rem + var(--safe-bottom));
  padding-left: calc(var(--gutter) + var(--safe-left));
  padding-right: calc(var(--gutter) + var(--safe-right));
  overflow-wrap: anywhere;
}

.settings-screen > .btn { margin-block: 1rem; }

.settings-section {
  border-block-start: 1px solid var(--line);
  padding-block: .75rem;
}

.settings-section h2 {
  margin: 0 0 .5rem;
  font-size: 1rem;
}

.settings-section p { margin: 0; color: var(--muted); }
.settings-section select { max-width: 100%; }
.caller-controls,
.microphone-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.caller-controls { margin-block-end: .5rem; }
.microphone-controls {
  margin-block-start: .5rem;
}
.microphone-controls p { flex-basis: 100%; }

.main {
  display: grid;
  grid-template-rows: minmax(180px, 1fr) auto auto;
  flex: 1 0 auto;
  gap: 8px;
  padding-block: 6px calc(10px + var(--safe-bottom));
  min-width: 0;
}

.current-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
}

.game-status {
  text-align: center;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 700;
}

.game-status:not(:empty) { padding-block: 0 4px; }

.card-content {
  container-type: size;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  text-align: center;
}

.card-content > .card-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 4px;
}

.card-content img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 3px 9px var(--shadow);
}

.placeholder {
  max-width: 28ch;
  padding: 10px;
  color: var(--muted);
}

.clue-card {
  display: grid;
  gap: 8px;
  max-height: 100%;
  overflow: auto;
  padding: 10px;
}

.clue-text {
  margin: 0;
  font: 700 clamp(1.1rem, 4vw, 2rem)/1.2 Georgia, serif;
  overflow-wrap: anywhere;
}

.clue-source {
  color: var(--muted);
  font-size: .8rem;
}

.dealt-section { min-width: 0; }

.dealt-section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: .875rem;
}

.dealt-section h2::before,
.dealt-section h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.dealt-strip {
  display: flex;
  min-height: 52px;
  gap: 8px;
  overflow-x: auto;
  padding: 1px 2px 4px;
  overscroll-behavior-inline: contain;
}

.dealt-strip .card-frame { flex: 0 0 auto; }
.dealt-strip img {
  display: block;
  width: auto;
  height: clamp(50px, 9dvh, 76px);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.accessible-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  border: 2px solid #15232a;
  border-radius: 9px;
  background: #fff9eb;
  color: #15232a;
  text-align: center;
}

.card-content .accessible-card {
  width: min(100%, 20rem);
  width: min(100%, 72cqh, 20rem);
  height: min(100%, 25rem);
  padding: .25rem .4rem .55rem;
}

.dealt-strip .accessible-card {
  width: 5.25rem;
  height: clamp(66px, 11dvh, 90px);
  padding: 2px 4px 4px;
  border-radius: 5px;
}

.accessible-card img {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.accessible-card-name {
  font-size: clamp(.95rem, 4cqh, 1.5rem);
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.dealt-strip .accessible-card-name { font-size: .75rem; }

.controls {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.btn {
  min-width: 44px;
  min-height: 44px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

.btn-primary {
  border-color: transparent;
  background: var(--coral);
  color: var(--on-coral);
  font-size: 1.125rem;
}

.btn-restart { border-color: var(--ink); }

@media (hover: hover) {
  .btn:not(:disabled):hover { background: var(--surface); }
  .btn-primary:not(:disabled):hover { background: var(--coral-hover); }
}

.btn.is-active { background: var(--surface); }

.speed-controls {
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
}

.speed-controls .btn {
  border: 0;
  border-radius: 0;
  font-size: 1.25rem;
}

.speed-controls .btn:first-child {
  border-inline-end: 1px solid var(--line);
  border-start-start-radius: 9px;
  border-end-start-radius: 9px;
}

.speed-controls .btn:last-child {
  border-inline-start: 1px solid var(--line);
  border-start-end-radius: 9px;
  border-end-end-radius: 9px;
}

#speed-label {
  padding-inline: 10px;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@media (orientation: landscape) and (min-width: 540px) {
  .topbar, .main { max-width: 1080px; }
  .topbar { padding-block-end: 2px; }
  .main {
    grid-template-columns: minmax(0, 1.2fr) minmax(170px, .8fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 8px clamp(12px, 3vw, 30px);
    min-height: 232px;
  }

  .current-card {
    grid-row: 1 / 3;
    padding-inline-end: clamp(10px, 2vw, 20px);
    border-inline-end: 1px solid var(--line);
  }

  .dealt-section { align-self: end; }
  .dealt-strip { min-height: 46px; }
  .dealt-strip img { height: clamp(40px, 10dvh, 76px); }
  .dealt-strip .accessible-card img { height: 100%; }
}

@media print {
  .topbar, .controls, .dealt-section { display: none; }
}
