html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  font-size: 16px;
}
body {
  background:
    radial-gradient(120% 60% at 50% 0%, #1f3438 0%, transparent 60%),
    var(--soot-900);
}
button { font: inherit; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
input { font: inherit; -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  position: relative;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen { position: absolute; inset: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); display: flex; flex-direction: column; padding: 14px 16px; gap: 12px; }
.screen.center { align-items: center; justify-content: center; }
.dim { color: var(--ink-dim); }
.small { font-size: 0.8rem; }
.mono { font-family: var(--font-mono); letter-spacing: 0.1em; color: var(--brass-300); }
.center-text { text-align: center; margin: 0; }

/* Join */
.logo { font-size: 3rem; margin: 0; color: var(--brass-300); text-shadow: 0 0 24px rgb(255 182 72 / 0.35); }
.logo span { color: var(--copper-400); }
.tagline { margin: 0 0 18px; font-style: italic; }
.join { width: 100%; max-width: 360px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.join label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.join input {
  height: 54px; border-radius: 8px; border: 2px solid var(--soot-600); background: var(--soot-900);
  color: var(--ink); padding: 0 14px; font-size: 1.3rem; outline: none; width: 100%;
  font-size: 16px; font-size: max(16px, 1.3rem); /* no iOS focus zoom */
}
.join input:focus { border-color: var(--brass-400); box-shadow: 0 0 0 3px rgb(217 178 90 / 0.25); }
.join input.code { text-align: center; text-transform: uppercase; letter-spacing: 0.4em; font-family: var(--font-mono); font-size: 1.8rem; }
.btn { min-height: 48px; }
.btn.go, .big-btn { width: 100%; min-height: 58px; font-size: 1.2rem; }
.msg { background: rgb(226 85 63 / 0.15); border: 1px solid var(--danger); color: #ffb3a6; padding: 10px 12px; border-radius: 8px; font-size: 0.95rem; }
.btn.sm { min-height: 44px; padding: 0.4em 0.9em; font-size: 0.95rem; flex: 1; }
.btn.ghost { background: linear-gradient(180deg, var(--soot-600), var(--soot-700)); color: var(--brass-300); }
.btn.on { background: linear-gradient(180deg, #8be0c8, var(--verdigris)); color: #06261d; border-color: #2a6e5c; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.5), 0 3px 0 #2a6e5c; }
.btn.danger { background: linear-gradient(180deg, #f08a76, var(--danger)); color: #2a0a04; border-color: #7a2a1c; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.4), 0 3px 0 #7a2a1c; }
.btn:disabled { filter: grayscale(0.8) brightness(0.6); }
.link { background: none; border: none; color: var(--ink-dim); text-decoration: underline; min-height: 44px; }

.gear.big { font-size: 4rem; color: var(--brass-400); }
.spin { animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Lobby */
.lobby-head { text-align: center; padding-top: 8px; }
.me-chip { display: inline-flex; align-items: center; gap: 10px; font-size: 2.2rem; margin: 4px 0; }
.dot { display: inline-block; width: 18px; height: 18px; border-radius: 50%; background: var(--brass-400); border: 2px solid rgb(255 255 255 / 0.5); flex: none; }
.plist { list-style: none; margin: 0; padding: 8px 12px; flex: 0 1 auto; overflow: auto; min-height: 0; }
.plist li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--soot-600); font-size: 1.15rem; }
.plist li:last-child { border: none; }
.plist .tag { margin-left: auto; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
.plist li.off { opacity: 0.5; }
.lobby-foot { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-top: auto; }

/* Game layout */
.game { padding: 8px 8px 8px; gap: 6px; }
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 10px; min-height: 50px; flex: none; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 1.25rem; font-family: var(--font-display); }
.stat b { font-weight: 700; min-width: 1.5ch; font-variant-numeric: tabular-nums; }
.stat .ico { font-size: 1.3rem; }
.ico.cog { color: var(--brass-400); }
.ico.heart { color: var(--danger); }
.stat.wave { flex-direction: column; gap: 0; line-height: 1.05; align-items: center; }
.stat.wave small { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-dim); font-family: var(--font-body); }
.stat.timer { color: var(--gas-glow); min-width: 64px; justify-content: flex-end; }
.stat.timer.idle { visibility: hidden; }
.bump { animation: bump 0.35s; }
@keyframes bump { 40% { transform: scale(1.25); color: var(--gas-glow); } }
.hurt { animation: hurt 0.5s; }
@keyframes hurt { 30% { color: #fff; transform: scale(1.3); } }

#mapwrap { position: relative; flex: 1; min-height: 0; border-radius: 10px; overflow: hidden; background: var(--soot-900); border: 2px solid var(--brass-700); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#under { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px; pointer-events: none; overflow: hidden; display: flex; flex-direction: column; justify-content: center; gap: 4px; font-size: 0.95rem; }
#under .ttl { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-dim); }
#under .wv { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink); }
#under .wv span b { color: var(--gas-glow); font-weight: 700; }
#under .wv .boss { color: var(--danger); }

#actions { display: flex; gap: 8px; flex: none; }
#panel { flex: 1 1 auto; padding: 10px; min-height: 150px; display: flex; flex-direction: column; gap: 8px; }
#panel .hint { margin: auto; text-align: center; color: var(--ink-dim); font-style: italic; padding: 8px; font-size: 1.1rem; line-height: 1.4; }

.cards { flex: 1; display: grid; grid-auto-rows: minmax(64px, 140px); align-content: center; grid-template-columns: 1fr 1fr; gap: 8px; }
.card { text-align: left; background: linear-gradient(170deg, var(--soot-600), var(--soot-800)); color: var(--ink); border: 2px solid var(--brass-700); border-radius: 10px; padding: 8px 10px; min-height: 66px; display: flex; flex-direction: column; gap: 2px; }
.card:active { transform: scale(0.97); }
.card .nm { font-family: var(--font-display); font-weight: 700; display: flex; justify-content: space-between; gap: 6px; font-size: 0.98rem; }
.card .cost { color: var(--brass-300); white-space: nowrap; }
.card .st { font-size: 0.78rem; color: var(--ink-dim); line-height: 1.25; }
.card.poor { opacity: 0.45; border-color: var(--soot-600); }
.card.poor .cost { color: var(--danger); }

.trow { display: flex; align-items: center; gap: 10px; }
.trow .dot { width: 16px; height: 16px; }
.trow .nm { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.trow .sub { font-size: 0.8rem; color: var(--ink-dim); }
.trow .pips { margin-left: auto; color: var(--brass-300); letter-spacing: 3px; font-size: 1.1rem; }
.brow { display: flex; gap: 8px; }
.brow .btn { flex: 1; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; padding: 0.3em 0.5em; }
.brow .btn small { font-family: var(--font-body); font-weight: 400; font-size: 0.7rem; opacity: 0.85; }
.brow .btn.sell { flex: 0 0 34%; }

.crank { position: relative; width: 100%; min-height: 84px; flex: 1 1 auto; max-height: 200px; border: 2px solid var(--copper-600); border-radius: 12px; background: linear-gradient(180deg, var(--copper-400), var(--copper-600)); color: #2a1004; font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; letter-spacing: 0.12em; overflow: hidden; touch-action: none; display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.4), 0 3px 0 #5a2c14; }
.crank .g { font-size: 2.2rem; display: inline-block; transition: transform 0.08s linear; }
.crank .fill { position: absolute; left: 0; bottom: 0; height: 100%; width: 0; background: linear-gradient(90deg, rgb(255 182 72 / 0.0), rgb(255 230 150 / 0.55)); border-right: 3px solid var(--gas-glow); pointer-events: none; transition: width 0.1s linear; }
.crank .lbl { position: relative; }
.crank .pct { position: relative; font-family: var(--font-mono); font-size: 0.85rem; font-weight: 700; min-width: 3.6ch; }
.crank.pressed { filter: brightness(1.15); transform: translateY(2px); }

/* Sheets, toast, banner */
.sheet, .overlay { position: absolute; inset: 0; z-index: 20; background: rgb(5 9 10 / 0.7); display: flex; align-items: flex-end; }
.overlay { align-items: center; justify-content: center; padding: 20px; z-index: 40; background: rgb(5 9 10 / 0.88); }
.ovl-body { padding: 22px; text-align: center; display: flex; flex-direction: column; gap: 12px; max-width: 340px; }
.ovl-body h2 { margin: 0; color: var(--brass-300); }
.sheet-body { width: 100%; border-radius: 16px 16px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; font-size: 1.2rem; }
.x { background: none; border: none; color: var(--ink); font-size: 2rem; width: 48px; height: 48px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 48px; padding: 0 14px; border-radius: 24px; border: 2px solid var(--soot-600); background: var(--soot-800); color: var(--ink); display: inline-flex; align-items: center; gap: 8px; font-size: 1rem; }
.chip.sel { border-color: var(--gas-glow); background: var(--soot-600); box-shadow: 0 0 12px rgb(255 182 72 / 0.4); }
.chip:disabled { opacity: 0.4; }
.amts .chip { flex: 1; justify-content: center; font-family: var(--font-mono); font-weight: 700; }
.toast { position: absolute; left: 12px; right: 12px; top: calc(env(safe-area-inset-top) + 58px); z-index: 30; padding: 10px 14px; border-radius: 10px; text-align: center; font-size: 0.98rem; pointer-events: none; animation: tin 0.2s ease-out; }
.toast.err { background: rgb(120 30 20 / 0.95); border: 1px solid var(--danger); color: #ffd7cf; }
.toast.ok { background: rgb(20 60 52 / 0.92); border: 1px solid var(--verdigris); color: #cdf5e9; font-size: 0.9rem; }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }
.banner { position: absolute; left: 0; right: 0; top: 0; z-index: 35; padding: calc(env(safe-area-inset-top) + 6px) 12px 6px; background: var(--danger); color: #fff; text-align: center; font-size: 0.9rem; }

/* End */
.end { overflow: hidden; }
.end h1 { text-align: center; font-size: 2.6rem; margin: 6px 0 0; }
.end.won h1 { color: var(--brass-300); text-shadow: 0 0 28px rgb(255 182 72 / 0.5); }
.end.lost h1 { color: var(--danger); }
.mine { padding: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.mine div b { display: block; font-family: var(--font-display); font-size: 1.5rem; color: var(--brass-300); }
.mine div span { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
.awards { display: flex; flex-direction: column; gap: 6px; overflow: auto; min-height: 0; flex: 1; }
.award { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--soot-800); border: 1px solid var(--soot-600); }
.award.me { border-color: var(--gas-glow); box-shadow: 0 0 10px rgb(255 182 72 / 0.3); }
.award .at { font-family: var(--font-display); font-weight: 700; color: var(--brass-300); }
.award .ad { font-size: 0.8rem; color: var(--ink-dim); }
.award .ap { margin-left: auto; font-size: 0.9rem; text-align: right; }

@media (max-height: 700px) {
  .logo { font-size: 2.4rem; }
  #panel { min-height: 130px; padding: 8px; }
  .card { min-height: 58px; padding: 6px 8px; }
  .crank { min-height: 66px; }
  .brow .btn { min-height: 48px; }
  .end h1 { font-size: 2rem; }
}

.game.zoomed #panel { flex: none; }
.game.zoomed .crank { flex: none; min-height: 72px; }
.game.zoomed .cards { grid-auto-rows: auto; }

/* ---- portrait-game rotate hint ---- */
.rotate { display: none; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 0 0 0 12px; min-height: 40px; border-radius: 8px; background: rgb(255 182 72 / 0.12); border: 1px solid var(--brass-700); color: var(--brass-300); font-size: 0.85rem; }
.rotate button { background: none; border: none; color: var(--ink); font-size: 1.6rem; width: 48px; height: 40px; }
@media (orientation: portrait) { .rotate:not([hidden]) { display: flex; } }
.brand { text-align: center; }

/* ---- landscape (phone held sideways) ---- */
@media (orientation: landscape) and (max-height: 560px) {
  .screen { padding: 8px 12px; gap: 8px; }
  .logo { font-size: 2.2rem; }
  .tagline { margin: 0 0 4px; }

  /* join: brand left, form right */
  .screen.center { flex-direction: row; gap: 28px; }
  .screen.center .brand { flex: 1; }
  .join { flex: 1; max-width: 380px; padding: 12px; gap: 8px; }
  .join input { height: 44px; }
  .join label { gap: 3px; font-size: 0.7rem; }
  .btn.go, .big-btn { min-height: 50px; }

  /* lobby: identity + buttons left, players right */
  #s-lobby { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; align-items: start; column-gap: 16px; }
  #s-lobby .lobby-head { grid-column: 1; grid-row: 1; padding: 0; }
  #s-lobby .me-chip { font-size: 1.8rem; }
  #s-lobby .plist { grid-column: 2; grid-row: 1 / 3; max-height: 100%; }
  #s-lobby .lobby-foot { grid-column: 1; grid-row: 2; align-self: end; width: 100%; }
  .plist li { padding: 6px 2px; font-size: 1rem; }

  /* end: summary left, awards right */
  #s-end { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto 1fr auto; column-gap: 16px; row-gap: 6px; }
  #s-end h1 { grid-column: 1; font-size: 1.7rem; margin: 0; }
  #s-end #endSub { grid-column: 1; font-size: 0.85rem; }
  #s-end .mine { grid-column: 1; align-self: start; padding: 8px; }
  #s-end .awards { grid-column: 2; grid-row: 1 / 5; }
  #s-end .lobby-foot { grid-column: 1; }
  .mine div b { font-size: 1.2rem; }

  /* game: map left at full height, controls right */
  .game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 37%); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "top act" "map panel"; gap: 6px; padding: 6px 8px; }
  #topbar { grid-area: top; min-height: 0; padding: 0 10px; }
  #actions { grid-area: act; }
  #mapwrap { grid-area: map; flex: none; height: auto !important; }
  #panel { grid-area: panel; min-height: 0; padding: 8px; gap: 6px; overflow: hidden; }
  .rotate { display: none !important; }
  .stat { font-size: 1.1rem; }
  .stat .ico { font-size: 1.1rem; }
  .stat.wave b { font-size: 1.05rem; }
  .stat.wave small { font-size: 0.55rem; }
  .btn.sm { min-height: 44px; padding: 0.2em 0.5em; font-size: 0.9rem; }
  .cards { grid-auto-rows: minmax(48px, 1fr); gap: 6px; align-content: stretch; }
  .card { min-height: 0; padding: 4px 8px; }
  .card .nm { font-size: 0.85rem; }
  .card .st { font-size: 0.68rem; line-height: 1.2; }
  .trow .nm { font-size: 1rem; }
  .trow .sub { font-size: 0.7rem; }
  .brow .btn { min-height: 48px; }
  .brow .btn small { font-size: 0.62rem; }
  .crank { min-height: 56px; max-height: none; font-size: 1.4rem; }
  #panel .hint { font-size: 0.95rem; }
  #under { font-size: 0.85rem; padding: 4px 10px; }
  .toast { top: 52px; left: 12px; right: 12px; }
  .game.zoomed #panel { flex: 1; }
  .game.zoomed .cards { grid-auto-rows: minmax(48px, 1fr); }
  .game.zoomed .crank { min-height: 56px; flex: 1 1 auto; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .toast { top: auto; bottom: 12px; right: calc(37% + 24px); left: 16px; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-body { max-width: 600px; border-radius: 14px; padding: 8px 12px; gap: 8px; }
  .sheet-head { font-size: 1rem; }
  .x { height: 40px; }
  .chip { min-height: 44px; }
  .sheet .big-btn { min-height: 48px; }
}
