/* Teacup Mahjong. The table's colours come from the table picked (game.js sets --felt-a, --felt-b, --felt-ink). */
:root {
  --felt-a: #1f5a48;
  --felt-b: #123a30;
  --felt-ink: #f3ecd8;
  --felt-glow: #2f7a62;
  --cream: #fbf4e2;
  --paper: #fffaf0;
  --ink: #2e2219;
  --ink-soft: #6a5646;
  --gold: #e8b54a;
  --gold-dark: #a8741c;
  --jade: #1f6a52;
  --red: #b8392f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; touch-action: manipulation; }

html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  position: fixed;
  inset: 0;
  font-family: "Baloo 2", ui-rounded, system-ui, sans-serif;
  color: var(--felt-ink);
  background: radial-gradient(ellipse 120% 80% at 50% 40%, var(--felt-glow), transparent 70%), linear-gradient(var(--felt-a), var(--felt-b));
  background-color: var(--felt-b);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body.table-teak { background-image: repeating-linear-gradient(92deg, rgba(0,0,0,.07) 0 3px, transparent 3px 11px, rgba(255,255,255,.04) 11px 13px, transparent 13px 23px), radial-gradient(ellipse 120% 80% at 50% 40%, var(--felt-glow), transparent 70%), linear-gradient(var(--felt-a), var(--felt-b)); }

button { font: inherit; color: inherit; }

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--sg-corner-top) 12px calc(var(--safe-bottom) + 10px);
  max-width: 640px;
  margin: 0 auto;
}

/* the header: the corner's menu button, the level and the clock, lined up with the button */
.top {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  min-height: 44px;
  padding-left: calc(var(--sg-corner-left) - 12px);
}
.title { text-align: center; line-height: 1.05; min-width: 0; }
.title h1 { margin: 0; font-size: clamp(21px, 6vw, 26px); font-weight: 800; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title p { margin: 1px 0 0; font-size: 15px; font-weight: 600; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock { margin: 0; text-align: right; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; opacity: .9; }
.clock.off { visibility: hidden; }

.status { margin: 4px 0 2px; min-height: 24px; text-align: center; font-size: 16px; font-weight: 600; opacity: .92; }

.stage { position: relative; flex: 1; min-height: 0; touch-action: none; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.tip {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); width: min(92%, 420px); margin: 0;
  padding: 10px 14px; border-radius: 14px; background: rgba(255, 250, 240, .95); color: var(--ink);
  font-size: 16px; font-weight: 600; line-height: 1.3; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.28); pointer-events: none;
}

/* the bottom bar: big, plain buttons */
.bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding-top: 8px; }
.ctl {
  min-height: 58px; border: 0; border-radius: 16px; background: rgba(255, 250, 240, .14); color: var(--felt-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 16px; font-weight: 700; cursor: pointer; box-shadow: inset 0 0 0 1.5px rgba(255,250,240,.22);
}
.ctl b { display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 2px; border-radius: 999px; background: var(--gold); color: #3a2608; font-size: 14px; line-height: 20px; }
.ctl.empty b { background: rgba(255,250,240,.25); color: var(--felt-ink); }
.ctl svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ctl:active { transform: scale(.96); background: rgba(255,250,240,.24); }
.ctl:disabled { opacity: .45; }
.ctl.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: inset 0 0 0 2.5px var(--gold), 0 0 16px rgba(232,181,74,.6); } }
.ctl:focus-visible, .primary:focus-visible, .secondary:focus-visible, .lv:focus-visible, .pick:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* cards and buttons */
.primary, .secondary {
  display: block; width: 100%; min-height: 54px; border: 0; border-radius: 16px; font-size: 19px; font-weight: 800; cursor: pointer;
}
.primary { background: linear-gradient(#f0c35e, #d99b2b); color: #3a2608; box-shadow: 0 3px 0 #9a6a14; }
.secondary { background: #efe5cf; color: var(--ink); box-shadow: 0 3px 0 #cbb994; }
.primary:active, .secondary:active { transform: translateY(2px); box-shadow: none; }

.stuck {
  position: fixed; z-index: 18; left: 50%; bottom: calc(var(--safe-bottom) + 12px); transform: translateX(-50%);
  width: min(calc(100vw - 24px), 440px); padding: 16px 16px 14px; border-radius: 22px; background: var(--paper); color: var(--ink);
  box-shadow: 0 10px 40px rgba(0,0,0,.45); text-align: center; animation: rise .3s ease-out;
}
.stuck h2 { margin: 0; font-size: 24px; font-weight: 800; }
.stuck p { margin: 4px 0 12px; font-size: 17px; line-height: 1.3; color: var(--ink-soft); }
.stuck-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stuck-btns .primary { grid-column: 1 / -1; }
.stuck-btns [hidden] { display: none; }
@keyframes rise { from { transform: translate(-50%, 30px); opacity: 0; } }

.win { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(10, 24, 18, .55); }
.win[hidden] { display: none; }
.win-card {
  width: min(100%, 400px); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 18px 18px 16px; border-radius: 26px;
  background: var(--paper); color: var(--ink); text-align: center; box-shadow: 0 18px 60px rgba(0,0,0,.5); animation: pop .4s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.win-art { height: 96px; display: grid; place-items: center; }
.win-art svg { height: 96px; width: auto; }
.win h2 { margin: 2px 0 0; font-size: 32px; font-weight: 800; color: var(--jade); }
.win-time { margin: 0 0 8px; font-size: 19px; font-weight: 700; color: var(--ink-soft); }
.win-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.win-list li { padding: 8px 12px; border-radius: 12px; background: #f4ecd8; font-size: 16px; font-weight: 600; line-height: 1.25; }
.win-list li.gold { background: #fbe7b4; }
.win-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.win-row .secondary { font-size: 17px; }

/* full screens: the Journey and the Tea Chest */
.screen { position: fixed; inset: 0; z-index: 16; display: flex; flex-direction: column; background: radial-gradient(ellipse 120% 80% at 50% 30%, var(--felt-glow), transparent 70%), linear-gradient(var(--felt-a), var(--felt-b)); background-color: var(--felt-b); }
.screen[hidden] { display: none; }
.screen-top { display: flex; align-items: center; gap: 12px; padding: var(--sg-corner-top) 16px 8px var(--sg-corner-left); }
.screen-top h2 { margin: 0; flex: 1; text-align: center; padding-right: 96px; font-size: 26px; font-weight: 800; }
.screen-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 6px 14px calc(var(--safe-bottom) + 24px); touch-action: pan-y; }
.screen-body > * { max-width: 560px; margin-left: auto; margin-right: auto; }

.chapter { margin: 0 auto 14px; padding: 12px; border-radius: 20px; background: rgba(255,250,240,.1); box-shadow: inset 0 0 0 1.5px rgba(255,250,240,.16); }
.chapter.locked { opacity: .6; }
.ch-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ch-head canvas { width: 56px; height: 64px; flex: none; }
.ch-head h3 { margin: 0; font-size: 21px; font-weight: 800; line-height: 1.1; }
.ch-head p { margin: 2px 0 0; font-size: 15px; opacity: .85; }
.lvs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.lv {
  position: relative; min-height: 48px; border: 0; border-radius: 12px; background: var(--cream); color: var(--ink); font-size: 18px; font-weight: 800;
  box-shadow: 0 3px 0 #b9a47a; cursor: pointer;
}
.lv.done { background: #d9efe2; box-shadow: 0 3px 0 #7fb196; }
.lv.clean::after { content: "★"; position: absolute; top: 1px; right: 4px; font-size: 12px; color: var(--gold-dark); }
.lv.next { background: linear-gradient(#f6d27a, #e3a73a); box-shadow: 0 3px 0 #9a6a14; }
.lv:disabled { background: rgba(255,250,240,.18); color: rgba(255,250,240,.6); box-shadow: none; }
.lv:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }

.chest-next { margin: 0 auto 16px; padding: 14px; border-radius: 18px; background: rgba(255,250,240,.12); }
.chest-next h3 { margin: 0 0 6px; font-size: 19px; }
.chest-sec { margin: 0 auto 6px; font-size: 20px; font-weight: 800; }
.picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.pick {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 120px; padding: 8px 4px; border: 0; border-radius: 16px;
  background: rgba(255,250,240,.12); color: var(--felt-ink); cursor: pointer; box-shadow: inset 0 0 0 1.5px rgba(255,250,240,.18);
}
.pick canvas { width: 72px; height: 72px; }
.pick span { font-size: 14px; font-weight: 700; line-height: 1.15; text-align: center; }
.pick small { font-size: 13px; opacity: .85; }
.pick.on { box-shadow: inset 0 0 0 3px var(--gold); background: rgba(232,181,74,.18); }
.pick:disabled { opacity: .55; }

.toast {
  position: fixed; z-index: 40; left: 50%; top: calc(var(--sg-corner-top) + 80px); transform: translate(-50%, -10px); width: max-content; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 14px; background: rgba(255,250,240,.97); color: var(--ink); font-size: 16px; font-weight: 700; line-height: 1.3; text-align: center;
  box-shadow: 0 8px 26px rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 29; pointer-events: none; }

/* sheets (How to play, Stats) */
.how-tiles { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 10px; }
.how-tiles canvas { width: 40px; height: 52px; }
.stat-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0 0 14px; font-size: 17px; }
.stat-grid b { text-align: right; }
.ach-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ach-list li { padding: 8px 10px; border-radius: 12px; background: rgba(0,0,0,.05); line-height: 1.25; }
.ach-list li b { display: block; font-size: 16px; }
.ach-list li span { font-size: 14px; opacity: .8; }
.ach-list li.got { background: #fbe7b4; }
.ach-list li.got b::before { content: "★ "; color: var(--gold-dark); }

/* Title screen: the shared layout (shared/mainmenu.js); these are only this game's colours. */
#mm {
  --sg-bg: radial-gradient(ellipse 120% 80% at 50% 30%, #2f7a62, transparent 70%), linear-gradient(#1f5a48, #0f3128);
  --sg-ink: #f6eed8; --sg-ink-soft: #cfe0d4;
  --sg-title: #f6d27a; --sg-title-shadow: 0 3px 0 #0b241d;
  --sg-accent: #e8b54a; --sg-accent-ink: #3a2608;
  --sg-card: rgba(255, 250, 240, .12); --sg-card-ink: #f6eed8; --sg-line: rgba(255, 250, 240, .2);
}
.sg-sheet { --sg-sheet-bg: #fffaf0; --sg-sheet-ink: #2e2219; --sg-accent: #d99b2b; --sg-accent-ink: #3a2608; --sg-ink-soft: #6a5646; }
.mj-title-art { width: 240px; height: auto; display: block; margin: 0 auto; image-rendering: pixelated; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }

@media (max-height: 700px) {
  .ctl { min-height: 52px; font-size: 15px; }
  .title p { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .stuck, .win-card, .ctl.pulse { animation: none !important; }
  .toast { transition: none; }
}

/* The tea house round the table (pixel art, Codex): a lantern wall over the top that fades into whichever felt is picked,
   and the teapot and cups at the table's near corners. Looks only; the board's canvas draws over them. */
.room { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.room .wall {
  position: absolute; left: 0; right: 0; top: 0; height: min(46vw, 34vh, 300px);
  background: url("assets/wall.webp") center top / cover no-repeat;
  -webkit-mask-image: linear-gradient(#000 45%, transparent); mask-image: linear-gradient(#000 45%, transparent);
  filter: brightness(.82) saturate(.95);
}
.room .pot, .room .cups { position: absolute; bottom: calc(var(--safe-bottom) + 82px); height: auto; opacity: .95; image-rendering: pixelated; }
.room .pot { left: 4px; width: min(22vw, 96px); }
.room .cups { right: 4px; width: min(26vw, 116px); }
.top h1, .top p, .clock { text-shadow: 0 1px 3px rgba(0,0,0,.65); }
