:root {
  color-scheme: light;
  --bg: #fff4df;
  --ink: #37251a;
  --muted: #7f6b5c;
  --panel: #fffdf8;
  --accent: #ff7a8a;
  --accent-dark: #d94d62;
  --gold: #ffd36a;
  --green: #58b889;
  --line: rgba(89, 58, 37, 0.16);
  --shadow: 0 20px 44px rgba(116, 79, 43, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 14%, rgba(255, 211, 106, 0.42), transparent 18rem),
    radial-gradient(circle at 86% 18%, rgba(223, 248, 232, 0.8), transparent 16rem),
    linear-gradient(145deg, #fff7e8 0%, #ffe9d4 48%, #f6fff4 100%);
}

button,
select,
input {
  font: inherit;
}

/* Touch feedback: kill the grey tap flash, add a quick press response */
button,
.mode-card {
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease;
}

button:active,
.mode-card:active {
  transform: scale(0.97);
}

.app {
  width: min(1120px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
  /* Respect notch / home-indicator safe areas inside the app shell */
  padding: calc(24px + env(safe-area-inset-top)) env(safe-area-inset-right)
    calc(24px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

.start-screen,
.result-screen {
  width: min(780px, 100%);
  padding: clamp(22px, 5vw, 44px);
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.brand-row,
.hud,
.result-actions,
.touch-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo-mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid rgba(55, 37, 26, 0.86);
  border-radius: 16px;
  background: var(--gold);
  font-weight: 900;
  letter-spacing: 0;
}

.language-select,
.text-input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
}

.brand-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.haptics-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.haptics-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.text-input {
  width: 100%;
  margin: 8px 0 18px;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.intro {
  margin: 42px 0 22px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  font-size: clamp(3rem, 8vw, 5.8rem);
  line-height: 1;
}

h2 {
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  line-height: 1;
}

h3 {
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.local-title {
  margin: 14px 0 0;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  font-weight: 900;
  color: #2d946c;
}

.subtitle,
.hint,
.result-copy,
.medical-note {
  max-width: 640px;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.55;
}

.how-to-play {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 22px;
}

.how-to-play div {
  min-height: 84px;
  padding: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
}

.how-to-play strong,
.how-to-play span {
  display: block;
}

.how-to-play strong {
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.how-to-play span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.mode-card {
  min-height: 108px;
  padding: 18px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  cursor: pointer;
}

.mode-card span,
.hud span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.mode-card strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.mode-card.is-selected {
  border-color: rgba(55, 37, 26, 0.86);
  background: #fff0b8;
  box-shadow: inset 0 0 0 2px rgba(55, 37, 26, 0.88);
}

.primary-button,
.secondary-button,
.drop-button {
  min-height: 50px;
  border-radius: 18px;
  cursor: pointer;
  font-weight: 850;
}

.primary-button {
  width: 100%;
  color: #fff;
  background: var(--accent);
  border: 0;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  padding: 0 18px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.game-screen {
  width: 100%;
}

.hud {
  margin-bottom: 12px;
  padding: 14px;
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.hud strong {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
}

canvas {
  display: block;
  margin: 0 auto;
  /* Portrait play area: a tall canvas fills the phone and gives real room to
     stack upward. Height-driven so it never overflows on desktop either. */
  aspect-ratio: 600 / 1040;
  height: min(68vh, 720px);
  width: auto;
  max-width: 100%;
  background: #fffdf8;
  border: 2px solid rgba(55, 37, 26, 0.85);
  border-radius: 26px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.color-preview {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 10px auto 2px;
}

.preview-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.preview-item span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.preview-item img {
  width: 40px;
  height: 43px;
  object-fit: contain;
}

.touch-zone {
  margin-top: 12px;
}

.drop-button {
  flex: 1;
  color: #fff;
  background: var(--green);
  border: 0;
}

.result-screen {
  text-align: center;
}

.result-score {
  margin: 24px auto 10px;
  font-size: clamp(4rem, 16vw, 8.5rem);
  line-height: 1;
  font-weight: 950;
  color: var(--accent);
}

.leaderboard,
.color-guide {
  margin-top: 26px;
  text-align: left;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.board-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.board-tab {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.board-tab.is-selected {
  background: var(--gold);
  color: var(--ink);
  border-color: rgba(55, 37, 26, 0.4);
}

.board-empty {
  padding: 16px 8px;
  color: var(--muted);
  text-align: center;
}

.board-country {
  white-space: nowrap;
}

.country-status {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(30, 20, 12, 0.5);
}

.confirm-box {
  width: min(340px, 88vw);
  padding: 26px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.confirm-box p {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink);
}

.confirm-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.confirm-actions button {
  flex: 1;
}

.color-guide-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.color-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.swatch {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
}

.color-card strong {
  display: block;
  margin-bottom: 2px;
}

.color-card span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.result-actions {
  margin-top: 28px;
}

/* Toilet-paper donation placeholder (native IAP comes in the app build) */
.support-box {
  margin-top: 26px;
  padding: 20px;
  text-align: left;
  background: linear-gradient(150deg, #fff6e6 0%, #ffeef1 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.support-copy {
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.5;
}

.support-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.support-button {
  min-height: 50px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid rgba(55, 37, 26, 0.5);
  border-radius: 16px;
  font-weight: 850;
  cursor: pointer;
}

.support-button:hover {
  background: var(--gold);
}

.support-note {
  margin: 14px 0 0;
  color: var(--accent-dark);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.45;
}

.is-hidden {
  display: none;
}

@media (max-width: 680px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding: 10px 0;
  }

  .start-screen,
  .result-screen {
    padding: 20px;
  }

  .intro {
    margin: 34px 0 20px;
  }

  .mode-grid,
  .result-actions,
  .color-guide-list,
  .how-to-play {
    grid-template-columns: 1fr;
    display: grid;
  }

  .mode-card {
    min-height: 86px;
  }

  .hud {
    gap: 8px;
  }

  .hud strong {
    font-size: 1.15rem;
  }

  th,
  td {
    padding: 8px 6px;
    font-size: 0.78rem;
  }
}
