/* Banners, parchment, ink and six standards. Fixed palette (the same in light and dark OS modes). */
:root {
  --bg: #f1ede6;
  --surface: #fffdf8;
  --surface2: #e4ddd0;
  --line: rgba(60, 48, 30, .14);
  --ink: #2b2519;
  --muted: #7a6c56;
  --accent: #8c3b2f;           /* you */
  --rival: #40546e;            /* your rival */
  --gold: #b8912f;
  --field: #e8e0d0;
  /* the six standards */
  --c0: #d59a26;  /* Amber */
  --c1: #c05a7a;  /* Rose */
  --c2: #3d7ba8;  /* Azure */
  --c3: #4f8a52;  /* Jade */
  --c4: #7d5fa8;  /* Violet */
  --c5: #5f6a74;  /* Slate */
  /* tutorial kit (tutorial.css) */
  --tut-accent: #b8912f;
  --tut-accent-ink: #2b2519;
  --tut-bubble: #fffdf8;
  --tut-ink: #2b2519;
  --tut-muted: #7a6c56;
  --tut-dim: rgba(30, 24, 12, .58);
  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: 760px; margin: 0 auto; padding: 0 10px 16px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }

/* ---------- top bar + menu ---------- */
.topbar { display: flex; align-items: center; gap: 4px; height: 50px; }
.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 21px/1 Georgia, "Times New Roman", serif; letter-spacing: .06em; color: var(--ink); }
.menu { position: absolute; right: 10px; top: 46px; z-index: 45; min-width: 200px; padding: 6px; background: var(--surface); border-radius: 14px; box-shadow: 0 14px 36px rgba(60, 48, 30, .25); 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: #d8cfbe; }
.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: #76301f; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

/* ---------- status ---------- */
.status { min-height: 38px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 4px 4px; font-size: 15px; color: var(--muted); text-align: center; position: relative; }
.status.mine { color: var(--ink); font-weight: 600; }
.status .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--rival); }
.status.mine .dot { background: var(--accent); }
.status .net-note { position: absolute; left: 50%; top: calc(100% - 6px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: calc(100% - 24px); background: var(--ink); color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 8px; }

/* ---------- the field: nine banners in one line ---------- */
.field { background: var(--field); border-radius: 16px; padding: 6px 6px 8px; box-shadow: inset 0 0 0 1px var(--line); }
.side-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--rival); padding: 2px 4px; min-height: 20px; }
.side-label.mine { color: var(--accent); }
.side-label .tally { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; font-size: 13px; }

.line { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 3px; align-items: stretch; }
.banner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px 1px; border: 0; background: none; border-radius: 10px; cursor: pointer; min-height: 150px; transition: background .15s, box-shadow .15s; }
.banner:disabled { cursor: default; }
.banner.can { background: rgba(184, 145, 47, .16); box-shadow: inset 0 0 0 1.5px rgba(184, 145, 47, .55); }
.banner.can:hover { background: rgba(184, 145, 47, .3); }
.banner.won0 { background: rgba(140, 59, 47, .1); }
.banner.won1 { background: rgba(64, 84, 110, .1); }
.banner.fresh { animation: flash .7s ease-out; }
@keyframes flash { from { background: rgba(184, 145, 47, .6); } to { background: rgba(184, 145, 47, 0); } }

/* a side's company: three small cards, overlapping towards the banner */
.side { display: flex; flex-direction: column; align-items: center; width: 100%; min-height: 54px; justify-content: flex-end; }
.side.top { justify-content: flex-start; }
.side .slot { height: 8px; }                 /* the empty places keep the banner's height steady */
.mark { display: grid; place-items: center; height: 26px; color: var(--gold); }
.mark .ico { width: 18px; height: 22px; }
.mark.taken0 { color: var(--accent); }
.mark.taken1 { color: var(--rival); }

/* ---------- cards ---------- */
.card { position: relative; width: 100%; max-width: 40px; aspect-ratio: 5 / 7; border-radius: 6px; border: 0; padding: 0; display: grid; place-items: center;
  color: #fff; font: 700 15px/1 system-ui, sans-serif; box-shadow: 0 1px 3px rgba(43, 37, 25, .35); }
.card .ini { position: absolute; top: 1px; left: 3px; font-size: 8px; font-weight: 700; opacity: .85; letter-spacing: .02em; }
.side .card { margin-top: -16px; }           /* overlap: the newest card sits in front */
.side.top .card { margin-top: 0; margin-bottom: -16px; }
.side .card:first-child { margin-top: 0; }
.side.top .card:last-child { margin-bottom: 0; }
.c0 { background: var(--c0); } .c1 { background: var(--c1); } .c2 { background: var(--c2); }
.c3 { background: var(--c3); } .c4 { background: var(--c4); } .c5 { background: var(--c5); }

/* ---------- your hand ---------- */
.you { margin-top: 10px; }
.hand { display: flex; gap: 5px; justify-content: center; align-items: flex-end; min-height: 96px; }
.hand .card { max-width: 46px; font-size: 19px; border-radius: 9px; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.hand .card .ini { font-size: 10px; top: 3px; left: 5px; }
.hand .card.on { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(43, 37, 25, .35); }
.hand .card:disabled { opacity: .45; cursor: default; }
.controls { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; font-size: 14px; color: var(--muted); }

/* ---------- sheets and modals ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(30, 24, 12, .45); }
.sheet { position: relative; width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; box-shadow: 0 -10px 40px rgba(43, 37, 25, .2); }
@keyframes up { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3 { font-size: 18px; margin-bottom: 6px; }
.sheet .lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 6px; }
.sheet .row { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.sheet .row .who { font-weight: 700; min-width: 84px; }
.sheet .row .cards { display: flex; gap: 4px; }
.sheet .row .cards .card { width: 34px; max-width: 34px; margin: 0; font-size: 14px; }
.sheet .kind { margin-left: auto; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.field-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.field-row .label { font-weight: 600; min-width: 96px; }
.seg { display: flex; gap: 4px; flex: 1; background: var(--surface2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 4px rgba(43, 37, 25, .2); }

.modal-wrap { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 14px; background: rgba(30, 24, 12, .45); }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(43, 37, 25, .3); }
.over-modal { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font: 700 19px/1.2 Georgia, "Times New Roman", serif; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.rules h3 { font-size: 15px; margin: 14px 0 4px; }
.rules ul, .rules ol { margin: 0; padding-left: 20px; }
.rules li { margin: 3px 0; }
.rules .kinds li { margin: 5px 0; }
.result-line { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.result-line .bar { height: 10px; border-radius: 5px; background: var(--surface2); flex: 1; overflow: hidden; }
.result-line .bar i { display: block; height: 100%; }
.result-line .bar i.me { background: var(--accent); }
.result-line .bar i.them { background: var(--rival); }

/* ---------- online ---------- */
body.is-online .hand .card:disabled { opacity: .5; }

@media (max-width: 400px) {
  .app { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .line { gap: 2px; }
  .banner { padding: 3px 0; }
  .hand { gap: 4px; }
}
@media (min-width: 620px) {
  .banner { min-height: 200px; }
  .card { max-width: 54px; }
  .side .card { margin-top: -22px; }
  .side.top .card { margin-bottom: -22px; }
  .hand .card { max-width: 62px; font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
