/* Driftholm: sky blues, cream paper panels, sunset-orange buttons. Portrait phones stack the board between
   the players and the hand; wide screens put the board left and everything else in a column on the right. */
:root {
  --ink: #2b2a33; --ink2: #5f5c68; --paper: #fffdf7; --paper2: #f3eee2; --line: #ddd3bf;
  --sky: #8fcdf3; --primary: #ef7d2d; --primary-ink: #ffffff; --primary-dark: #b6531a;
  --shadow: 0 6px 18px rgba(30, 50, 80, 0.18);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--sky); color: var(--ink); font-family: var(--font);
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; overscroll-behavior: none;
  -webkit-text-size-adjust: 100%; touch-action: manipulation; }
#app { position: fixed; inset: 0; overflow: hidden; }
#layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
input { font: inherit; -webkit-user-select: text; user-select: text; }
svg { display: inline-block; vertical-align: middle; flex: none; }
h1, h2, h3, h4 { font-weight: 800; }

/* ---------- buttons ---------- */
.big { display: block; padding: 14px 16px; border-radius: 14px; font-size: 18px; font-weight: 800; background: #fff;
  box-shadow: inset 0 0 0 2px var(--line), 0 2px 0 rgba(0, 0, 0, 0.05); }
.big.primary, .act.primary { background: var(--primary); color: var(--primary-ink); box-shadow: inset 0 -3px 0 var(--primary-dark); }
.big:active, .act:active, .bld:active, .rp:active { transform: translateY(1px); }
.wide { width: 100%; }
.big.wide { margin-top: 10px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.row.gap { margin: 8px 0; }
.toggle { padding: 8px 14px; border-radius: 999px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); font-weight: 700; font-size: 15px; }
.toggle.on { background: #e2f2ff; box-shadow: inset 0 0 0 2px #7cb5df; }
.act { flex: 1; min-width: 0; padding: 12px 8px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 800; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.act:disabled, .bld:disabled, .rp:disabled { opacity: 0.4; }
.act.wide { display: flex; margin-top: 8px; }
.act.armed { background: #fde3d2; box-shadow: inset 0 0 0 2px var(--primary); }
.roll { font-size: 20px; padding: 13px 8px; }
.bico { width: 26px; height: 26px; }

/* ---------- home ---------- */
.home { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--sky); }
.homeart { position: relative; flex: 1; min-height: 0; }
.homeart canvas { position: absolute; left: 0; top: 0; }
.homecard { flex: none; width: min(92vw, 420px); margin: 0 auto max(16px, env(safe-area-inset-bottom)); background: rgba(255, 253, 247, 0.94);
  border-radius: 22px; padding: 16px 16px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 9px; text-align: center; }
.logo { margin: 0; font-size: 44px; letter-spacing: 0.5px; color: #2c5c8c; line-height: 1.05; }
.tag { margin: -2px 0 4px; color: var(--ink2); font-weight: 600; }
.ver { margin: 2px 0 0; font-size: 12px; color: var(--ink2); }

/* ---------- scrolling screens (new game, how to play) ---------- */
.screen { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(14px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom)); background: linear-gradient(#7cc3f0, #e9f6ff 70%); }
.panelcard { max-width: 540px; margin: 0 auto; background: var(--paper); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); }
.panelcard h2 { margin: 2px 0 8px; font-size: 26px; }
.field { margin: 14px 0; }
.field > .lbl { font-weight: 800; margin-bottom: 6px; }
.field > .hint { font-size: 13px; color: var(--ink2); margin-top: 5px; }
.seg { display: flex; background: var(--paper2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 10px 6px; border-radius: 10px; font-weight: 800; color: var(--ink2); }
.seg button.sel { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14); }
.seat { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.swatch { width: 42px; height: 42px; border-radius: 50%; background: var(--pc); box-shadow: inset 0 0 0 3px var(--pd); flex: none; }
.seat input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-size: 17px; color: var(--ink); }
.rules h4 { margin: 16px 0 4px; }
.rules p, .rules li { font-size: 15px; line-height: 1.4; }
.rules ul, .rules ol { padding-left: 20px; margin: 4px 0; }
.costs { list-style: none; padding-left: 0 !important; }
.costs li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cardline { display: flex; gap: 10px; align-items: center; }

/* ---------- game table ---------- */
.game { position: absolute; inset: 0; display: grid; grid-template-columns: 100%;
  grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-areas: "top" "status" "stage" "panel";
  padding-top: env(safe-area-inset-top); }
.top { grid-area: top; display: flex; gap: 6px; padding: 6px 8px 2px; }
.chips { flex: 1; display: flex; gap: 5px; min-width: 0; }
.chip { flex: 1; min-width: 0; background: var(--paper); border-radius: 12px; padding: 4px 7px 5px; display: grid;
  grid-template-columns: auto minmax(0, 1fr); column-gap: 5px; align-items: center; font-size: 13px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); border: 2px solid transparent; }
.chip.turn { border-color: var(--pc); box-shadow: 0 0 0 2px var(--pl), 0 2px 8px rgba(0, 0, 0, 0.18); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--pc); box-shadow: inset 0 0 0 2px var(--pd); flex: none; }
.cname { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { grid-column: 1 / -1; display: flex; gap: 7px; align-items: center; flex-wrap: nowrap; overflow: hidden; }
.stat { display: inline-flex; align-items: center; gap: 2px; font-weight: 800; }
.mini { width: 15px; height: 15px; }
.iconbtn { width: 44px; flex: none; border-radius: 12px; background: var(--paper); font-size: 22px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12); }
.status { grid-area: status; padding: 3px 10px; font-weight: 800; text-align: center; font-size: 15px; min-height: 24px; color: #1d3b5a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6); }
.stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; }
.stage canvas { position: absolute; left: 0; top: 0; touch-action: none; }
.dice { position: absolute; left: 8px; top: 6px; display: flex; gap: 5px; align-items: center; pointer-events: none; }
.die { width: 36px; height: 36px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.dl { font-size: 11px; font-weight: 800; color: #2c4a66; background: rgba(255, 255, 255, 0.75); border-radius: 8px; padding: 2px 6px; margin-left: 2px; }
.toasts { position: absolute; left: 50%; transform: translateX(-50%); top: 48px; display: flex; flex-direction: column; gap: 4px;
  align-items: center; pointer-events: none; width: 94%; }
.toast { background: rgba(30, 38, 54, 0.85); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 700;
  transition: opacity 0.5s; text-align: center; max-width: 100%; }
.toast.err { background: rgba(176, 42, 42, 0.94); }
.toast.fade { opacity: 0; }
.panel { grid-area: panel; padding: 7px 8px max(8px, env(safe-area-inset-bottom)); background: rgba(255, 253, 247, 0.93);
  border-radius: 18px 18px 0 0; box-shadow: 0 -4px 14px rgba(30, 50, 80, 0.12); }
.hand { display: flex; gap: 5px; min-height: 58px; }
.handhidden { flex: 1; display: grid; place-items: center; color: var(--ink2); font-weight: 700; }
.rcard { flex: 1; min-width: 0; background: #fff; border-radius: 10px; box-shadow: inset 0 0 0 2px var(--line); display: flex;
  flex-direction: column; align-items: center; padding: 3px 1px 3px; }
.rcard.none { opacity: 0.45; }
.rcard.sky { background: #e6f3ff; box-shadow: inset 0 0 0 2px #9ccbee; }
.rico { width: 28px; height: 28px; }
.rcard .n { font-weight: 800; font-size: 17px; line-height: 1.05; }
.rcard .rn { font-size: 10px; color: var(--ink2); white-space: nowrap; overflow: hidden; max-width: 100%; }
.actions { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.bldrow, .actrow { display: flex; gap: 6px; }
.bld { flex: 1; min-width: 0; background: #fff; border-radius: 12px; padding: 5px 2px; box-shadow: inset 0 0 0 2px var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bl { font-weight: 800; font-size: 14px; }
.cost { display: inline-flex; gap: 0; flex-wrap: wrap; justify-content: center; }
.ci { width: 15px; height: 15px; }
.wait { text-align: center; color: var(--ink2); margin: 10px 4px; font-weight: 700; }

/* ---------- sheets ---------- */
.sheet { position: absolute; inset: 0; pointer-events: none; display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet.open { pointer-events: auto; background: rgba(20, 30, 45, 0.28); }
.sheetbox { position: relative; width: 100%; max-width: 560px; max-height: 86%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--paper); border-radius: 20px 20px 0 0; padding: 14px 12px max(16px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25); }
.sheetbox.anim { animation: up 0.16s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheetbox h3 { margin: 0 0 10px; font-size: 20px; padding-right: 40px; }
.sheetbox h3.win { font-size: 30px; color: var(--pd); }
.close { position: absolute; right: 10px; top: 9px; width: 36px; height: 36px; border-radius: 50%; background: var(--paper2); font-size: 24px; line-height: 1; }
.lbl { font-weight: 800; margin: 10px 0 5px; font-size: 14px; }
.hint { font-size: 13px; color: var(--ink2); margin: 8px 0 0; }
.respick, .steps { display: flex; gap: 5px; }
.rp, .step { flex: 1; min-width: 0; background: #fff; border-radius: 10px; box-shadow: inset 0 0 0 2px var(--line); padding: 5px 1px;
  display: flex; flex-direction: column; align-items: center; font-size: 11px; gap: 1px; }
.rp.sel { box-shadow: inset 0 0 0 3px var(--primary); background: #fff3e8; }
.step.on { box-shadow: inset 0 0 0 2px #e9a36e; background: #fff8f1; }
.rate { font-weight: 800; font-size: 14px; }
.have { color: var(--ink2); white-space: nowrap; }
.ctl { display: flex; align-items: center; gap: 1px; }
.ctl button { width: 24px; height: 28px; border-radius: 8px; background: var(--paper2); font-weight: 800; font-size: 18px; line-height: 1; }
.ctl button:disabled { opacity: 0.3; }
.ctl .n { min-width: 14px; text-align: center; font-weight: 800; font-size: 15px; }
.deal { display: flex; align-items: stretch; gap: 8px; }
.dside { flex: 1; text-align: center; background: var(--paper2); border-radius: 12px; padding: 4px 8px 10px; }
.arrow { display: grid; place-items: center; font-size: 22px; color: var(--ink2); }
.resicons { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.ri { width: 30px; height: 30px; }
.whom { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.pchip { flex: 1; min-width: 30%; padding: 12px 8px; border-radius: 12px; background: #fff; box-shadow: inset 0 0 0 3px var(--pc); font-weight: 800; display: flex; flex-direction: column; align-items: center; }
.pchip.sel { background: var(--pl); }
.pchip .small { font-size: 12px; font-weight: 600; color: var(--ink2); }
.cardrow { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cardpic { width: 52px; height: 70px; border-radius: 10px; background: var(--cc); display: grid; place-items: center; flex: none;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.45), 0 2px 4px rgba(0, 0, 0, 0.15); }
.cardpic.small { width: 36px; height: 48px; border-radius: 8px; }
.cardpic.small .cico { width: 28px; height: 28px; }
.cico { width: 40px; height: 40px; }
.cardtxt { flex: 1; min-width: 0; }
.cardtxt p { margin: 2px 0; font-size: 13px; line-height: 1.3; }
.why { color: #a24d1d; font-weight: 700; }
.act.play { flex: none; padding: 12px 16px; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.log li { padding: 5px 2px; border-bottom: 1px solid var(--line); }
.score { width: 100%; border-collapse: collapse; font-size: 14px; }
.score th { font-size: 11px; color: var(--ink2); text-align: center; padding: 3px 2px; }
.score td { text-align: center; padding: 7px 2px; border-top: 1px solid var(--line); }
.score td:first-child { text-align: left; font-weight: 800; white-space: nowrap; }
.score td:first-child .dot { margin-right: 5px; vertical-align: -1px; }
.score .tot { font-weight: 800; font-size: 18px; }

/* ---------- pass the phone ---------- */
.cover { position: absolute; inset: 0; display: none; z-index: 30; background: rgba(110, 170, 220, 0.6); align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.cover.open { display: flex; }
.coverbox { background: var(--paper); border-radius: 22px; padding: 20px 20px 18px; width: min(88vw, 380px); text-align: center; box-shadow: var(--shadow);
  border-top: 10px solid var(--pc); }
.coverbox .small { margin: 0; color: var(--ink2); font-weight: 700; }
.pname { margin: 2px 0 6px; font-size: 36px; color: var(--pd); overflow-wrap: anywhere; }

.flyer { position: absolute; left: 0; top: 0; width: 30px; height: 30px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3)); }

/* ---------- wide screens: board left, everything else in a column on the right ---------- */
@media (min-aspect-ratio: 5/4) and (min-width: 600px) {
  .game { grid-template-columns: minmax(0, 1fr) minmax(290px, 370px); grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "stage top" "stage status" "stage panel"; padding-right: env(safe-area-inset-right); }
  .chips { flex-wrap: wrap; }
  .chip { flex: 1 1 40%; }
  .panel { border-radius: 18px 0 0 0; align-self: end; }
  .sheet { justify-content: flex-end; }
  .sheetbox { max-width: 400px; max-height: 100%; border-radius: 20px 0 0 0; }
  .home { flex-direction: row; }
  .homecard { align-self: center; margin: 0 max(16px, env(safe-area-inset-right)) 0 0; }
}
@media (max-height: 640px) and (max-aspect-ratio: 5/4) {
  .rico { width: 24px; height: 24px; }
  .act { padding: 10px 6px; }
}
