:root {
  --ink: #17212b;
  --muted: #5e6b75;
  --panel: #ffffff;
  --line: #d7dee4;
  --good: #20795b;
  --bad: #b94a3c;
  --accent: #1c6ca1;
  --shadow: 0 18px 50px rgba(28, 42, 55, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

html,
body {
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(230, 241, 211, 0.8), transparent 24rem),
    radial-gradient(circle at 84% 18%, rgba(199, 232, 241, 0.9), transparent 25rem),
    linear-gradient(135deg, #eef4ef 0%, #edf5f8 48%, #f7efe6 100%);
}

.rotate-phone {
  display: none;
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid #1b617f;
  border-radius: 8px;
  color: #ffffff;
  background: #1c6ca1;
  cursor: pointer;
  padding: 0 16px;
  font-weight: 700;
}

button:hover {
  background: #145a87;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 126, 179, 0.28);
  outline-offset: 2px;
}

.app-shell {
  width: min(1320px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.game-panel,
.side-panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(188, 202, 213, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-panel {
  padding: 18px;
}

.side-panel {
  padding: 18px;
  display: grid;
  gap: 18px;
}

.top-bar {
  display: flex;
  gap: 18px;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--good);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1.05;
}

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

.controls-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

select,
input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  padding: 0 12px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  padding: 10px 12px;
  display: grid;
  align-content: center;
  gap: 2px;
}

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

.stat strong {
  font-size: 1.4rem;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid #aebcc7;
  border-radius: 8px;
  background: #dfeaf1;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  touch-action: none;
  user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 24, 30, 0.24);
}

.overlay.hidden {
  display: none;
}

.overlay-box {
  width: min(420px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 22px;
}

.overlay-box p {
  color: var(--muted);
  line-height: 1.55;
}

.how-to-play {
  color: var(--muted);
  line-height: 1.45;
}

.how-to-play h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.98rem;
}

.how-to-play ul {
  margin: 0 0 16px;
  padding-left: 20px;
}

.how-to-play li {
  margin: 6px 0;
}

.how-to-play strong {
  color: var(--ink);
}

.caught-summary {
  margin: 14px 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8f5;
  padding: 12px;
}

.caught-summary h3 {
  margin: 0 0 8px;
  color: var(--bad);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.caught-summary ul {
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
}

.caught-summary li {
  margin: 4px 0;
}

.overlay-box button,
.name-field,
.name-field input {
  width: 100%;
}

.mobile-controls {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
  touch-action: manipulation;
}

.mobile-controls button {
  min-height: 54px;
}

.rules,
.leaderboard {
  min-width: 0;
}

.rules {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.rules summary {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 1.05rem;
  font-weight: 800;
}

.rules summary::after {
  content: "+";
  color: var(--accent);
  font-size: 1.3rem;
  line-height: 1;
}

.rules[open] summary {
  margin-bottom: 10px;
}

.rules[open] summary::after {
  content: "-";
}

.points-list {
  display: grid;
  gap: 8px;
}

.point-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 9px 10px;
  font-size: 0.93rem;
}

.point-row strong {
  color: var(--good);
}

.point-row.penalty strong {
  color: var(--bad);
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 10px;
}

.leaderboard-head h2 {
  margin-bottom: 0;
}

.leaderboard-head span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.leaderboard-list {
  margin: 0;
  padding-left: 24px;
}

.leaderboard-list li {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.leaderboard-list li:last-child {
  border-bottom: 0;
}

.leaderboard-list .empty {
  list-style: none;
  color: var(--muted);
  padding-left: 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}

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

  .game-panel,
  .side-panel {
    padding: 12px;
  }

  .top-bar {
    display: grid;
    align-items: start;
  }

  .controls-row {
    justify-content: start;
  }

  .status-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat {
    min-height: 58px;
  }

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

  .mobile-controls {
    display: grid;
  }

  .overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    padding: 12px;
    background: rgba(15, 24, 30, 0.52);
  }

  .overlay-box {
    width: min(560px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    overflow: auto;
    padding: 14px;
  }

  .overlay-box button[type="button"],
  .overlay-box button[type="submit"] {
    position: sticky;
    bottom: 0;
    min-height: 46px;
    margin-top: 8px;
  }

  .overlay-box h2 {
    margin-bottom: 6px;
    font-size: 1rem;
  }

  .how-to-play {
    font-size: 0.82rem;
    line-height: 1.28;
  }

  .how-to-play h3 {
    margin-bottom: 5px;
    font-size: 0.9rem;
  }

  .how-to-play ul {
    margin-bottom: 10px;
    padding-left: 18px;
  }

  .how-to-play li {
    margin: 3px 0;
  }
}

@media (max-width: 520px) {
  .status-grid {
    grid-template-columns: 1fr;
  }

  button,
  select {
    width: 100%;
  }

  .controls-row {
    width: 100%;
  }

  .field {
    width: 100%;
  }
}

@media (hover: none) and (pointer: coarse) {
  .mobile-controls {
    display: grid;
  }

  .canvas-wrap {
    min-height: 0;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  body {
    overflow: auto;
  }

  .app-shell {
    filter: none;
    pointer-events: auto;
  }

  .rotate-phone {
    display: none;
  }

  .rotate-phone div {
    width: min(320px, 100%);
    border: 1px solid rgba(188, 202, 213, 0.9);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
    padding: 20px;
    display: grid;
    gap: 8px;
    text-align: center;
  }

  .rotate-phone strong {
    color: var(--good);
    font-size: 1.35rem;
  }

  .rotate-phone span {
    color: var(--muted);
    font-weight: 700;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  body {
    min-height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    padding: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(184px, 22vw);
    gap: 8px;
    align-items: stretch;
  }

  .game-panel,
  .side-panel {
    padding: 8px;
    min-height: 0;
  }

  .game-panel {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 6px;
  }

  .top-bar {
    margin-bottom: 0;
    gap: 10px;
    align-items: center;
  }

  .eyebrow {
    font-size: 0.62rem;
  }

  h1 {
    font-size: 1.35rem;
  }

  .controls-row {
    gap: 6px;
  }

  .field {
    font-size: 0.68rem;
  }

  button,
  select,
  input {
    min-height: 34px;
  }

  button {
    border-radius: 7px;
    padding: 0 10px;
    font-size: 0.78rem;
  }

  select {
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .status-grid {
    margin-bottom: 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .stat {
    min-height: 44px;
    padding: 5px 8px;
  }

  .stat span {
    font-size: 0.58rem;
  }

  .stat strong {
    font-size: 0.95rem;
  }

  .canvas-wrap {
    align-self: stretch;
  }

  #gameCanvas {
    height: 100%;
    aspect-ratio: auto;
  }

  .overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    padding: 10px;
    background: rgba(15, 24, 30, 0.48);
  }

  .overlay-box {
    width: min(560px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    overflow: auto;
    padding: 14px;
  }

  .overlay-box button[type="button"],
  .overlay-box button[type="submit"] {
    position: sticky;
    bottom: 0;
    min-height: 42px;
    margin-top: 8px;
  }

  .overlay-box h2 {
    margin-bottom: 6px;
    font-size: 0.95rem;
  }

  .how-to-play {
    font-size: 0.72rem;
    line-height: 1.22;
  }

  .how-to-play h3 {
    margin-bottom: 4px;
    font-size: 0.8rem;
  }

  .how-to-play ul {
    margin-bottom: 10px;
    padding-left: 17px;
  }

  .how-to-play li {
    margin: 2px 0;
  }

  .mobile-controls {
    margin-top: 0;
    gap: 8px;
  }

  .mobile-controls button {
    min-height: 44px;
  }

  .side-panel {
    gap: 8px;
    overflow: auto;
  }

  .leaderboard-head {
    display: grid;
    gap: 2px;
    margin-bottom: 6px;
  }

  .leaderboard-head h2,
  .rules summary {
    font-size: 0.9rem;
  }

  .leaderboard-head span,
  .leaderboard-list,
  .point-row {
    font-size: 0.72rem;
  }

  .leaderboard-list {
    padding-left: 18px;
  }

  .leaderboard-list li {
    padding: 6px 0;
  }

  .rules {
    padding-top: 8px;
  }

  .rules summary {
    min-height: 36px;
  }

  .points-list {
    gap: 6px;
  }

  .point-row {
    padding: 6px 7px;
    gap: 7px;
  }

  body.game-active .app-shell {
    width: 100vw;
    height: 100dvh;
    padding: 0;
    grid-template-columns: 1fr;
    gap: 0;
  }

  body.game-active .game-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #000000;
    padding: 0;
    grid-template-rows: minmax(0, 1fr);
  }

  body.game-active .top-bar,
  body.game-active .side-panel,
  body.game-active .mobile-controls {
    display: none;
  }

  body.game-active .status-grid {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin: 0;
    padding: max(6px, env(safe-area-inset-top)) 6px 6px;
    background: linear-gradient(180deg, rgba(10, 19, 26, 0.72), rgba(10, 19, 26, 0));
    pointer-events: none;
  }

  body.game-active .stat {
    min-height: 36px;
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.84);
    padding: 4px 6px;
  }

  body.game-active .stat span {
    font-size: 0.52rem;
  }

  body.game-active .stat strong {
    font-size: 0.86rem;
  }

  body.game-active .canvas-wrap {
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  body.game-active #gameCanvas {
    width: 100vw;
    height: 100dvh;
  }

  body.game-active .overlay {
    padding: 12px;
  }
}
