/*
 * Mobile-first: the base rules target iPhone Safari at 320-430px and the wider
 * layouts are additive. Presentation only - the render-state contract and the
 * engine are untouched.
 */
:root {
  --ink: #10231a;
  --paper: #f4f6f2;
  --line: #cfd8cf;
  --bat: #1b5e20;
  --opp: #7a2020;
  --ball: #f9a825;
  --tap: 44px;
  --gutter: 12px;
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
/* Layout rules below set display on these elements, so [hidden] has to win. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  padding: 0 var(--safe-left) var(--safe-bottom) var(--safe-right);
  overflow-wrap: break-word;
}
header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--gutter) 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
h1 { font-size: 17px; margin: 0; }
.scope { font-size: 12px; color: #5c6b5f; }
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.hud b { font-weight: 600; }
main {
  display: flex;
  flex-direction: column;
  gap: var(--gutter);
  padding: var(--gutter);
}
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: var(--gutter);
}
.setup {
  margin: var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.setup label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
select, input, button {
  font: inherit;
  /* 16px keeps iOS Safari from zooming the page when a field is focused. */
  font-size: 16px;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}
button {
  cursor: pointer;
  background: var(--bat);
  color: #fff;
  border-color: var(--bat);
  touch-action: manipulation;
}
button.ghost { background: none; color: #5c6b5f; border-color: var(--line); }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 16px 0 6px; color: #5c6b5f; }
svg {
  width: 100%;
  height: auto;
  background: #e8efe6;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: block;
}
.last { margin-top: 10px; font-size: 13px; min-height: 40px; }
.last .outcome { font-weight: 600; }
.options { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.options button {
  text-align: left;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  /* 44px keeps every card a comfortable iPhone touch target. */
  min-height: 44px;
  padding: 12px;
}
.options button.selected {
  border-color: var(--bat);
  box-shadow: inset 0 0 0 2px var(--bat);
  font-weight: 600;
}
.commit { position: sticky; bottom: 0; padding-top: 10px; background: #fff; }
.selection { margin: 0 0 6px; font-size: 13px; color: #5c6b5f; min-height: 18px; }
.confirm {
  min-height: 52px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.history { font-size: 12px; margin: 0; padding-left: 18px; color: #3f4c42; }
.history .opponent { color: var(--opp); }

/* Pointer devices get hover feedback; touch devices must not get stuck in it. */
@media (hover: hover) {
  .options button:hover { border-color: var(--bat); }
}

/* Tall phones can scroll the option list independently once there is room. */
@media (min-height: 700px) {
  .options { max-height: 46vh; overflow: auto; }
  .history { max-height: 22vh; overflow: auto; }
}

@media (min-width: 700px) {
  :root { --gutter: 20px; }
  header { flex-direction: row; align-items: baseline; gap: 18px; }
  .setup { flex-direction: row; align-items: flex-end; flex-wrap: wrap; gap: 16px; }
  .setup h2 { width: 100%; }
  select, input, button { width: auto; }
  .options button { width: 100%; }
}

@media (min-width: 900px) {
  main {
    display: grid;
    grid-template-columns: minmax(360px, 1.4fr) minmax(320px, 1fr);
    align-items: start;
  }
}

/*
 * Installed from the Home Screen there is no browser chrome to absorb a rubber
 * band or a long-press callout, so the standalone window behaves like an app.
 */
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }
  h1, .hud, .options button { -webkit-touch-callout: none; }
}
