/* RICE RIOT: how everything except the rice looks.
   Tour: colours and sizes are named once at the top (:root). Then: the table and tray, the top buttons,
   the tool strip, the one-line message, the start / pause / sticker screens.
   The buttons move to the side edges when the phone is turned sideways (body.o90 / body.o270). */
@font-face { font-family: 'Gochi Hand'; src: url('fonts/gochi-hand.woff2') format('woff2'); font-display: swap; }

:root {
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
  --table: #c98f5a; --table-dark: #a8713f;
  --tray: #eef0ec; --tray-edge: #d9d3c6; --tray-night: #1b2033;
  --ink: #3a2a1c; --ink-soft: #6b5743; --paper: #fff8ea;
  --btn: #fffdf7; --btn-edge: #b98a5c; --btn-press: #efe3cf;
  --go: #1f7a4d; --go-press: #18613d; --on-go: #ffffff;
  --pick: #ffd34d; --pick-edge: #c98a00;
  --shade: rgba(40, 24, 8, 0.55);
  --hud: 3.625rem; --strip: 4.5rem;
  --font: 'Gochi Hand', 'Comic Sans MS', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--table); color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; touch-action: manipulation; }

/* ---------- table and tray ---------- */
#table { position: fixed; inset: 0; background: radial-gradient(120% 90% at 50% 40%, var(--table) 0%, var(--table-dark) 100%); }
#bin { position: absolute; left: 0; top: 0; border-radius: 1.1rem; background: var(--tray);
  box-shadow: 0 0 0 0.3rem var(--tray-edge), 0 0 0 0.45rem #fff, 0 0.5rem 1.2rem rgba(40, 24, 8, 0.45), inset 0 0 1.4rem rgba(90, 70, 40, 0.28);
  transition: background-color 1.6s ease; }
body.night #bin { background: var(--tray-night); }
#under, #over { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#under { transition: filter 1.6s ease; }
body.night #under { filter: brightness(0.3); }
/* glow rice: the whole room dims a little, not just the tray */
#hud, #strip { transition: filter 1.6s ease; }
body.night #hud, body.night #strip { filter: brightness(0.62); }
body.night #table { background: radial-gradient(120% 90% at 50% 40%, #6d4d31 0%, #4f3520 100%); }
#rice { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.spr { position: absolute; left: 0; top: 0; will-change: transform; pointer-events: none; }
.spr.tap { pointer-events: auto; }
.toy { filter: drop-shadow(0 0.1rem 0.12rem rgba(0, 0, 0, 0.35)); }
.jar { filter: drop-shadow(0.3rem 0.5rem 0.5rem rgba(30, 18, 6, 0.45)); }
.visitor { filter: drop-shadow(0.1rem 0.2rem 0.15rem rgba(30, 18, 6, 0.4)); }
.cursor { filter: drop-shadow(0.15rem 0.25rem 0.2rem rgba(30, 18, 6, 0.35)); }
.fly { transition: transform 0.75s cubic-bezier(0.5, -0.3, 0.6, 1), opacity 0.75s ease-in; z-index: 5; }
.spark { position: absolute; left: 0; top: 0; width: 0.6rem; height: 0.6rem; margin: -0.3rem 0 0 -0.3rem; border-radius: 50%;
  background: #fff6b0; box-shadow: 0 0 0.5rem 0.15rem #ffd34d; pointer-events: none; animation: spark 0.7s ease-out forwards; }
@keyframes spark { from { opacity: 1; transform: translate(var(--x0), var(--y0)) scale(1); } to { opacity: 0; transform: translate(var(--x1), var(--y1)) scale(0.2); } }

/* ---------- top buttons ---------- */
#hud { position: fixed; display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; pointer-events: none;
  left: calc(var(--sal) + 0.5rem); right: calc(var(--sar) + 0.5rem); top: calc(var(--sat) + 0.3rem); height: 3rem; }
.hbtn { pointer-events: auto; position: relative; flex: none; width: min(3rem, 13.4vw); height: 3rem; border-radius: 0.9rem; border: 0.125rem solid var(--btn-edge);
  background: var(--btn); box-shadow: 0 0.15rem 0 var(--btn-edge); padding: 0; display: flex; align-items: center; justify-content: center; }
.hbtn:active, .hbtn.down { background: var(--btn-press); transform: scale(0.95); }
.hbtn canvas { width: 2.3rem; height: 2.3rem; }
.hbtn.wide { width: auto; min-width: min(5.6rem, 25vw); padding: 0 0.6rem 0 0.3rem; gap: 0.2rem; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.ic { display: block; width: 1.4rem; height: 1.4rem; position: relative; }
/* two upright bars: pause */
.ic-menu { background: linear-gradient(var(--ink), var(--ink)) 18% 0 / 24% 100% no-repeat, linear-gradient(var(--ink), var(--ink)) 82% 0 / 24% 100% no-repeat; border-radius: 0.1rem; }
.ic-x::before, .ic-x::after { content: ''; position: absolute; left: 45%; top: 0; width: 12%; height: 100%; background: var(--ink); border-radius: 0.1rem; }
.ic-x::before { transform: rotate(45deg); } .ic-x::after { transform: rotate(-45deg); }
/* the sticker book and pause card start below the top buttons, so their own buttons are never under a finger that just pressed one */
#book.overlay, #pause.overlay { padding-top: calc(var(--sat) + var(--hud) + 0.4rem); }
#btnTip .ring { position: absolute; inset: -0.125rem; border-radius: 0.9rem; pointer-events: none;
  background: conic-gradient(var(--go) calc(var(--hold, 0) * 1turn), transparent 0); opacity: 0.55; }

/* ---------- tool strip ---------- */
#strip { position: fixed; display: flex; justify-content: center; gap: 0.0625rem;
  left: calc(var(--sal) + 0.25rem); right: calc(var(--sar) + 0.25rem); bottom: calc(var(--sab) + 0.35rem); height: 3.75rem; }
.tool { position: relative; flex: 1 1 0; min-width: 0; max-width: 4.2rem; height: 100%; border-radius: 0.8rem; border: 0.125rem solid var(--btn-edge);
  background: var(--btn); box-shadow: 0 0.15rem 0 var(--btn-edge); padding: 0; display: flex; align-items: center; justify-content: center; }
.tool canvas { width: 2.7rem; height: 2.7rem; max-width: 96%; max-height: 92%; object-fit: contain; pointer-events: none; }
.tool:active { background: var(--btn-press); }
.tool.on { background: var(--pick); border-color: var(--pick-edge); box-shadow: 0 0.15rem 0 var(--pick-edge), 0 0 0 0.15rem #fff; transform: scale(0.96); }
.tool .puff { position: absolute; left: 12%; right: 12%; bottom: 0.2rem; height: 0.3rem; border-radius: 0.2rem; background: rgba(58, 42, 28, 0.2); overflow: hidden; }
.tool .puff b { display: block; height: 100%; width: 100%; background: #2f8fd8; transform-origin: left center; }

/* sideways: the tray keeps its place, so the buttons go to the short edges */
body.o90 #hud, body.o270 #hud { flex-direction: column; top: calc(var(--sat) + 0.5rem); bottom: calc(var(--sab) + 0.5rem); height: auto; width: 3rem; }
body.o90 #hud { left: calc(var(--sal) + 0.3rem); right: auto; }
body.o270 #hud { right: calc(var(--sar) + 0.3rem); left: auto; }
body.o90 .hbtn.wide, body.o270 .hbtn.wide { width: 3rem; min-width: 0; height: 4.4rem; flex-direction: column; padding: 0.2rem 0; font-size: 1rem; }
body.o90 #strip, body.o270 #strip { flex-direction: column; top: calc(var(--sat) + 0.25rem); bottom: calc(var(--sab) + 0.25rem); height: auto; width: 3.75rem; }
body.o90 #strip { right: calc(var(--sar) + 0.35rem); left: auto; }
body.o270 #strip { left: calc(var(--sal) + 0.35rem); right: auto; }
body.o90 .tool, body.o270 .tool { min-width: 0; max-width: none; width: 100%; min-height: 0; max-height: 4.2rem; }

/* ---------- one-line message (sits over the top buttons' row, never over the rice) ---------- */
#note { flex: 1 1 0; min-width: 0; max-height: 3rem; padding: 0.25rem 0.6rem; border-radius: 1rem; background: var(--paper); border: 0.125rem solid var(--btn-edge);
  font-size: clamp(0.85rem, 4.4vw, 1.1rem); line-height: 1.15; text-align: center; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; pointer-events: none; }
#note.off { visibility: hidden; }
/* sideways there is no room beside the buttons: a small line at the very top edge */
body.o90 #note, body.o270 #note { position: fixed; left: 50%; top: calc(var(--sat) + 0.15rem); transform: translateX(-50%); flex: none; max-width: 60%; max-height: 1.8rem; padding: 0.1rem 0.7rem; font-size: 1rem; -webkit-line-clamp: 1; white-space: nowrap; z-index: 6; }
body.o90 #btnMenu, body.o270 #btnMenu { margin-bottom: auto; }

/* ---------- screens ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: var(--shade);
  padding: calc(var(--sat) + 1rem) calc(var(--sar) + 1rem) calc(var(--sab) + 1rem) calc(var(--sal) + 1rem); touch-action: manipulation; }
.overlay.hidden { display: none; }
.card { width: min(22rem, 100%); max-height: 100%; overflow: auto; background: var(--paper); border-radius: 1.5rem; border: 0.2rem solid var(--btn-edge);
  padding: 1.1rem 1.2rem 1rem; text-align: center; box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.35); }
.card .logo { pointer-events: none; width: 6rem; height: 6rem; border-radius: 1.3rem; display: block; margin: 0 auto 0.2rem; }
h1 { font-size: 2.9rem; margin: 0; line-height: 1.05; font-weight: 400; }
h2 { font-size: 2rem; margin: 0 0 0.5rem; font-weight: 400; }
.card p { font-size: 1.3rem; line-height: 1.3; margin: 0.4rem 0 0.9rem; }
.card p.small { font-size: 1rem; color: var(--ink-soft); margin: 0.8rem 0 0; }
button.big { display: block; width: 100%; min-height: 3.6rem; border-radius: 1.1rem; border: 0; background: var(--go); color: var(--on-go);
  font-size: 1.9rem; box-shadow: 0 0.25rem 0 var(--go-press); margin: 0 0 0.9rem; }
button.big:active { background: var(--go-press); transform: scale(0.98); }
button.plain, button.opt { min-height: 3rem; border-radius: 0.9rem; border: 0.125rem solid var(--btn-edge); background: var(--btn); font-size: 1.25rem; padding: 0 0.6rem; }
button.plain { display: block; width: 100%; margin: 0 0 0.7rem; }
button.plain:active, button.opt:active { background: var(--btn-press); transform: scale(0.98); }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.row .opt { flex: 1 1 auto; min-width: 0; white-space: nowrap; font-size: clamp(1rem, 5vw, 1.25rem); }
/* a card that would not fit the screen (sideways, or big text): drop the picture and tighten up so Play stays in view */
body.tight .card .logo { display: none; }
body.tight h1 { font-size: 2rem; }
body.tight .card p { margin: 0.2rem 0 0.5rem; font-size: 1.1rem; }
body.tight .card { padding-top: 0.6rem; padding-bottom: 0.6rem; }
body.tight button.big { min-height: 3rem; margin-bottom: 0.5rem; font-size: 1.6rem; }
body.tight .card p.small { display: none; }
.wait { opacity: 0.6; }

.panel { width: min(30rem, 100%); max-height: 100%; display: flex; flex-direction: column; background: var(--paper); border-radius: 1.5rem;
  border: 0.2rem solid var(--btn-edge); box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.35); overflow: hidden; }
.panel header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.7rem 0.8rem 0.2rem 1.1rem; }
.panel header h2 { margin: 0; min-width: 0; font-size: clamp(1.4rem, 7.5vw, 2rem); }
.panel .sub { font-size: 1.15rem; margin: 0 1.1rem 0.5rem; color: var(--ink-soft); line-height: 1.25; }
.grid { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 0.3rem 0.8rem 1rem; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr)); gap: 0.5rem; }
.stk { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0.15rem; padding: 0.4rem 0.2rem 0.3rem; min-height: 6rem;
  border-radius: 0.8rem; border: 0.125rem dashed var(--tray-edge); background: #fff; font-size: 0.95rem; line-height: 1.1; text-align: center; }
.stk img { width: 3.2rem; height: 3.2rem; object-fit: contain; pointer-events: none; }
.stk.got { border-style: solid; border-color: var(--pick-edge); background: #fff7d6; }
.stk.miss img { filter: brightness(0) opacity(0.14); }
.stk.miss span { color: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) { .fly { transition-duration: 0.01s; } .spark { animation-duration: 0.01s; } }
