/* Paper Town, graph-paper palette, fixed (the same in light and dark OS modes). */
:root {
  --bg: #f1ede3;
  --paper: #fffdf7;
  --surface: #fffdf7;
  --surface2: #e7e1d2;
  --grid: rgba(60, 96, 150, .10);
  --line: rgba(38, 50, 74, .14);
  --ink: #27324a;
  --pen: #2c5aa8;
  --muted: #7a7d86;
  --accent: #d0543c;          /* you */
  --good: #3f8a4b;
  --hedge: #4c8a4a;
  --pond: #3f7fae;
  --gold: #e2b441;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e2b441;
  --tut-accent-ink: #27324a;
  --tut-bubble: #ffffff;
  --tut-ink: #27324a;
  --tut-muted: #7a7d86;
  --tut-dim: rgba(30, 38, 58, .55);
  --hand: "Segoe Print", "Bradley Hand", "Chalkboard SE", "Noteworthy", "Comic Sans MS", "Comic Neue", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; touch-action: manipulation; min-height: 100vh; overflow-x: hidden; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex: none; }

.app { position: relative; max-width: 560px; margin: 0 auto; padding: 0 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

/* ---------- top bar + menu ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 48px; }
.back, .iconbtn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 22px; background: none; border: 0; cursor: pointer; padding: 0; }
.back:hover, .iconbtn:hover, .iconbtn[aria-expanded="true"] { color: var(--ink); background: var(--surface2); }
.brand { flex: 1; text-align: center; font: 700 20px/1 var(--hand); letter-spacing: .02em; color: var(--pen); }
.menu { position: absolute; right: 12px; top: 44px; z-index: 45; min-width: 190px; padding: 6px; background: var(--surface); border-radius: 14px; box-shadow: 0 14px 36px rgba(38, 50, 74, .22); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.menu button { min-height: 46px; text-align: left; padding: 0 14px; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 600; }
.menu button:hover, .menu button:focus-visible { background: var(--surface2); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- buttons ---------- */
.btn { min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 0; background: var(--surface2); color: var(--ink); cursor: pointer; font-weight: 650; transition: background .15s, transform .1s, opacity .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { background: #dcd5c3; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #b94731; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 6px; margin: 0 0 2px; }
.pchip { position: relative; flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 7px; padding: 4px 8px; border: 0; border-radius: 14px; background: var(--surface); cursor: pointer; text-align: left; transition: box-shadow .2s; }
.pchip.cur { box-shadow: inset 0 -3px 0 var(--pc); }
.pchip .av { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--pc); color: #fff; font-weight: 800; font-size: 13px; }
.pchip .cinfo { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; flex: 1; }
.pchip .nm { font-size: 12px; color: var(--muted); white-space: normal; overflow-wrap: anywhere; line-height: 1.15; }
.pchip .line { display: flex; align-items: center; gap: 6px; }
.pchip .sc { font-size: 17px; font-weight: 800; }
.pchip .rf { font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: -1px; }
.pchip .done { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); display: inline-block; }
.chips.n3 .nm, .chips.n4 .nm { display: none; }
.chips.n4 .pchip { gap: 5px; padding: 4px 6px; }
.chips.n4 .pchip .av { width: 22px; height: 22px; font-size: 12px; }
.bubble { position: absolute; inset: 0; z-index: 2; border-radius: inherit; display: flex; align-items: center; justify-content: center; gap: 4px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--pc); animation: bubble 2.6s ease-out forwards; pointer-events: none; font-weight: 800; font-size: 18px; font-family: var(--hand); color: var(--pen); }
.bubble .ico { width: 22px; height: 22px; }
@keyframes bubble { 0% { opacity: 0; transform: scale(.9); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- status ---------- */
.status { min-height: 32px; display: flex; align-items: center; gap: 8px; padding: 0 2px 2px; font-size: 15px; color: var(--muted); }
.status.mine { color: var(--ink); font-weight: 600; }
.status .msg { flex: 1; min-width: 0; }
.status .turnno { flex: none; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--surface); border-radius: 8px; padding: 2px 7px; }
.status .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.thinking::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- plan cards ---------- */
.offer { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 6px; }
.pcard { position: relative; min-height: 72px; border: 0; border-radius: 12px; background: var(--paper); box-shadow: 0 1px 0 var(--line), 0 2px 6px rgba(38, 50, 74, .08); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px 6px 9px; overflow: hidden; transition: transform .15s, box-shadow .2s, opacity .2s; }
.pcard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--fxc); }
.pcard .num { font: 700 32px/1 var(--hand); color: var(--pen); }
.pcard .fxrow { display: flex; align-items: center; gap: 4px; max-width: 100%; }
.pcard .fx { width: 20px; height: 20px; flex: none; }
.pcard .fxname { font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard.sel { box-shadow: 0 0 0 3px var(--accent); transform: translateY(-2px); }
.pcard.idle { cursor: default; }
.pcard.nofit { opacity: .45; }
.pcard.fresh { animation: arrive .45s ease-out; }
.fx-hedge { --fxc: #4c8a4a; } .fx-garden { --fxc: #e07a96; } .fx-pond { --fxc: #3f7fae; }
.fx-handy { --fxc: #f0a24a; } .fx-twin { --fxc: #9a78c9; } .fx-appraise { --fxc: #e2b441; }
@keyframes arrive { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- goals ---------- */
.goals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 6px; }
.goal { position: relative; min-height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 3px 8px; border-radius: 10px; background: rgba(255, 253, 247, .6); border: 1px dashed rgba(38, 50, 74, .22); font-size: 12px; color: var(--muted); }
.goal .shape { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.goal .blk { display: inline-flex; gap: 1px; }
.goal .blk i { width: 5px; height: 9px; border-radius: 1px; background: var(--ink); opacity: .65; }
.goal .pts { font-weight: 800; color: var(--ink); white-space: nowrap; }
.goal .pts small { font-weight: 600; color: var(--muted); }
.goal.mine { background: #e5f0e2; border: 1px solid #9cc39a; }
.goal.mine .pts { color: var(--good); }
.goal .who { position: absolute; top: -4px; right: -3px; display: flex; gap: 2px; }
.goal .who span { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--bg); }

/* ---------- the sheet ---------- */
.sheet-paper { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 8px; border-radius: 14px; background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 14px 14px; box-shadow: 0 1px 0 var(--line), 0 3px 12px rgba(38, 50, 74, .08); }
.street { display: flex; flex-direction: column; min-width: 0; }
.shead { height: 26px; display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 0 2px; }
.shead .sn { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gdots { display: flex; gap: 2px; flex: none; }
.gdots i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid #6aa85e; }
.gdots i.on { background: #6aa85e; }
.lot { position: relative; height: 40px; width: 100%; display: flex; align-items: center; gap: 4px; padding: 0 6px 0 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: default; text-align: left; }
.lot .hs { width: 14px; height: 14px; color: rgba(38, 50, 74, .28); flex: none; }
.lot .v { flex: 1; font: 700 23px/1 var(--hand); color: var(--pen); text-align: center; }
.lot .tw { position: absolute; left: 20px; bottom: 3px; font-size: 9px; font-weight: 800; color: #6b4f99; letter-spacing: .03em; }
.lot .pd { width: 20px; height: 13px; flex: none; opacity: .35; }
.lot .pd.on { opacity: 1; }
.lot.built .hs { color: var(--pen); }
.lot.locked { background: rgba(226, 180, 65, .16); }
.lot.legal { cursor: pointer; background: rgba(208, 84, 60, .07); box-shadow: inset 0 0 0 2px rgba(208, 84, 60, .55); border-radius: 8px; border-bottom-color: transparent; }
.lot.dim .v, .lot.dim .hs { opacity: .45; }
.lot.preview { background: #fde9e2; box-shadow: inset 0 0 0 2px var(--accent); border-radius: 8px; cursor: pointer; }
.lot.preview .v { color: var(--accent); }
.lot.ttarget { cursor: pointer; box-shadow: inset 0 0 0 2px #9a78c9; border-radius: 8px; background: rgba(154, 120, 201, .08); }
.lot.tchosen { background: #efe6fb; box-shadow: inset 0 0 0 2px #6b4f99; border-radius: 8px; }
.lot.tchosen .v { color: #6b4f99; }
.lot.fresh { animation: fresh 1.4s ease-out; }
@keyframes fresh { 0% { background: rgba(208, 84, 60, .35); } 100% { background: transparent; } }
.gap { position: relative; height: 0; z-index: 2; }
.gap .hg { position: absolute; left: 2px; right: 2px; top: -4px; height: 8px; border-radius: 4px; background: var(--hedge); box-shadow: 0 1px 0 rgba(0, 0, 0, .15);
  background-image: radial-gradient(circle at 4px 4px, #6aa85e 3px, transparent 3.5px); background-size: 9px 8px; }
.gap .hg.new { background-color: #2f6a2e; animation: fresh-h 1.4s ease-out; }
@keyframes fresh-h { 0% { transform: scaleX(.3); } 100% { transform: none; } }
.gap .ghit { position: absolute; left: 0; right: 0; top: -20px; height: 40px; border: 0; background: transparent; cursor: pointer; padding: 0; z-index: 3; }
.gap .ghit::after { content: ''; position: absolute; left: 10px; right: 10px; top: 18px; height: 4px; border-radius: 2px; background: repeating-linear-gradient(90deg, var(--hedge) 0 5px, transparent 5px 10px); opacity: .5; }
.gap .ghit.on::after { height: 8px; top: 16px; background: var(--hedge); opacity: 1; }
.sheet-paper.hedging .lot { opacity: .8; }

/* ---------- actions ---------- */
.actions-row { position: sticky; bottom: 0; z-index: 10; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 56px; padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(rgba(241, 237, 227, 0), var(--bg) 30%); }
.actions-row:empty { min-height: 12px; padding: 0; }
.actions-row .grow { flex: 1 1 auto; max-width: 260px; }
.vals { display: flex; gap: 6px; width: 100%; justify-content: center; }
.vals button { min-width: 44px; min-height: 44px; border: 0; border-radius: 12px; background: var(--surface); cursor: pointer; font: 700 20px/1 var(--hand); color: var(--pen); box-shadow: 0 1px 0 var(--line); }
.vals button.on { background: var(--pen); color: #fff; }
.vals button:disabled { opacity: .3; cursor: not-allowed; }
.sizes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; width: 100%; }
.sizes button { min-height: 46px; border: 0; border-radius: 12px; background: var(--surface); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; box-shadow: 0 1px 0 var(--line); padding: 2px; }
.sizes button b { font-size: 15px; }
.sizes button small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.sizes button.on { box-shadow: inset 0 0 0 2px #a37a16; background: #fbf1d4; }
.sizes button:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- drawer (bottom sheet) ---------- */
.drawer-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(38, 50, 74, .35); }
.drawer { position: relative; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; box-shadow: 0 -10px 40px rgba(38, 50, 74, .2); }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer h3 { font: 700 19px/1.2 var(--hand); margin-bottom: 8px; color: var(--pen); }
.drawer p { margin: 6px 0; }
.drawer .actions { display: flex; gap: 8px; margin-top: 14px; }
.drawer .actions .btn { flex: 1 1 0; white-space: nowrap; }
.drawer .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 12px 0 5px; }
.drawer .sheet-paper { margin-bottom: 10px; }
.drawer .sheet-paper .lot { height: 30px; }
.drawer .sheet-paper .lot .v { font-size: 18px; }
.drawer .sheet-paper .gap .hg { top: -3px; height: 6px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: 13px; }
.log li { padding: 5px 2px; border-bottom: 1px solid var(--line); color: var(--muted); }
.log li:first-child { color: var(--ink); }
.setup-sheet .field { margin: 12px 0; }
.setup-sheet .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1 1 0; min-width: 0; min-height: 46px; border-radius: 12px; border: 0; background: var(--surface2); cursor: pointer; font-weight: 650; }
.seg button.on { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }

/* score table */
.table-wrap { overflow-x: auto; }
.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores th, .scores td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores thead th { color: var(--muted); font-size: 12px; font-weight: 600; }
.scores td .ico { width: 18px; height: 18px; margin-right: 4px; }
.scores tr.tot td { font-weight: 900; font-size: 15px; border-bottom: 0; }
.scores td.me, .scores th.me { color: var(--accent); }

/* ---------- modals ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(38, 50, 74, .4); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(38, 50, 74, .3); }
.over-modal { max-width: 480px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.modal-head h2 { font: 700 21px/1.2 var(--hand); color: var(--pen); }
.modal-body { padding: 0 18px 14px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }
.modal-foot .btn { flex: 1 1 110px; }
.rules h3 { font-size: 15px; margin: 16px 0 4px; color: var(--pen); }
.rules p, .rules li { font-size: 14px; }
.rules ol, .rules ul { padding-left: 20px; margin: 4px 0; }
.rules li { margin: 4px 0; }
.crew-rules { list-style: none; padding-left: 0 !important; }
.crew-rules li { display: flex; gap: 10px; align-items: flex-start; }
.crew-rules .ico { width: 26px; height: 26px; }
.result-banner { font: 800 26px/1.2 var(--hand); margin: 0 0 8px; color: var(--ink); }
.result-banner.win { color: var(--accent); }

@media (min-width: 700px) {
  .app { max-width: 600px; }
  .lot { height: 42px; }
  .status { justify-content: center; font-size: 16px; }
  .status .msg { flex: 0 1 auto; }
  .drawer-wrap { align-items: center; }
  .drawer { border-radius: 20px; }
}
@media (max-width: 400px) {
  .gdots { gap: 1px; }
  .gdots i { width: 7px; height: 7px; border-width: 1.2px; }
  .shead .sn { letter-spacing: 0; }
}
@media (max-width: 370px) {
  .pcard .num { font-size: 28px; }
  .lot { height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- online (a table with friends: tables.js) ---------- */
/* a short notice (connection lost, the table was updated, a friend left) floats just under the status line,
   over the cards' top edge, so the sheet never moves */
.status-wrap { position: relative; }
.net-note { position: absolute; left: 50%; top: calc(100% + 2px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(38, 50, 74, .3); pointer-events: none; animation: net-fade .25s ease-out; }
@keyframes net-fade { from { opacity: 0; } to { opacity: 1; } }
.net-note[hidden] { display: none; }
/* a friend who is away: the chip says so */
.pchip.fin .nm { color: var(--ink); font-weight: 650; }
.pchip:disabled { cursor: default; }
/* a divider between the game rows (new game, online) and the help rows */
.menu #menu-help { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
