:root{
  --bg:#f4f3ee;
  --ink:#44423c;
  --muted:#a39d90;
  --tile:#fffdf8;
  --tile-border:#e6e2d8;
  --tile-shadow:rgba(120,110,90,.16);
  --op:#ece6da;
  --op-ink:#6f685b;
  --accent:#e0a44d;
  --accent-ink:#7a5413;
  --good:#6f9e58;
  --good-bg:#e7efdd;
  --bad:#c47a68;
  --radius:16px;
  --tile-size:clamp(44px,13vw,64px);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;}
html,body{height:100%;}
body{
  margin:0;background:var(--bg);color:var(--ink);
  font-family:ui-rounded,"SF Pro Rounded",-apple-system,BlinkMacSystemFont,"Segoe UI",
    "Helvetica Neue",system-ui,sans-serif;
  font-weight:600;
  display:flex;justify-content:center;align-items:flex-start;min-height:100dvh;
  touch-action:manipulation;overflow-x:hidden;-webkit-user-select:none;user-select:none;
}
#app{width:100%;max-width:480px;
  padding:max(18px,env(safe-area-inset-top)) 16px max(18px,env(safe-area-inset-bottom));
  display:flex;flex-direction:column;gap:16px;}

.modes{display:flex;gap:6px;padding:4px;background:#ece7dc;border-radius:13px;align-self:center;}
.modebtn{border:none;background:transparent;color:var(--op-ink);font:inherit;font-weight:800;
  font-size:.9rem;padding:7px 16px;border-radius:10px;cursor:pointer;}
.modebtn.active{background:var(--tile);color:var(--ink);box-shadow:0 1px 2px var(--tile-shadow);}

header{display:flex;align-items:center;justify-content:space-between;}
.clockwrap{display:flex;flex-direction:column;gap:5px;align-items:flex-start;}
.clock{font-size:2.7rem;font-weight:800;letter-spacing:.02em;line-height:1;}
.clock.date{font-size:1.8rem;font-variant-numeric:tabular-nums;}
.fmt{border:1px solid var(--tile-border);background:var(--tile);color:var(--op-ink);
  font:inherit;font-weight:800;font-size:.72rem;padding:3px 10px;border-radius:8px;cursor:pointer;
  box-shadow:0 1px 0 var(--tile-shadow);}
.fmt[hidden]{display:none;}
.timer{font-size:1.15rem;font-weight:700;color:var(--muted);font-variant-numeric:tabular-nums;}
.timer.urgent{color:var(--bad);}

.scores{display:flex;gap:22px;font-size:.78rem;color:var(--muted);text-transform:uppercase;letter-spacing:.08em;}
.scores b{display:block;color:var(--ink);font-size:1.45rem;font-weight:800;letter-spacing:0;margin-top:2px;
  text-transform:none;font-variant-numeric:tabular-nums;}

/* daily histogram: how today's score compares to other players */
.hist{display:flex;flex-direction:column;gap:5px;padding:2px;}
.hist[hidden]{display:none;}
.hist .htitle{font-size:.72rem;color:var(--muted);text-transform:uppercase;letter-spacing:.08em;font-weight:800;}
.hist .hrow{display:flex;align-items:center;gap:8px;font-size:.82rem;font-variant-numeric:tabular-nums;}
.hist .hscore{width:1.7em;text-align:right;color:var(--op-ink);font-weight:800;}
.hist .hbarwrap{flex:1;background:#f0ece3;border-radius:7px;overflow:hidden;height:18px;}
.hist .hbar{display:block;height:100%;width:0;background:#cdc1a8;border-radius:7px;min-width:3px;transition:width .35s ease;}
.hist .hrow.you .hbar{background:var(--accent);}
.hist .hrow.you .hscore{color:var(--accent-ink);}
.hist .hcount{width:2.6em;color:var(--muted);font-weight:700;}
.hist .hfoot{font-size:.74rem;color:var(--muted);text-align:center;margin-top:1px;}

.banner{text-align:center;padding:12px;border-radius:14px;background:#f6ead2;color:var(--accent-ink);font-weight:800;}
.banner[hidden]{display:none;}

/* equation strip: locked digit tiles + inserted symbol tiles, with insert gaps */
.board{
  display:flex;flex-wrap:wrap;align-items:center;justify-content:center;
  row-gap:6px;padding:14px 6px;min-height:calc(var(--tile-size) + 28px);
  background:#fbfaf5;border:1px solid var(--tile-border);border-radius:var(--radius);
  transition:background .25s ease,border-color .25s ease;
}
.board.valid{background:var(--good-bg);border-color:#cfe0bd;}
.board.arming{background:#fbf6ea;}

.digit{
  flex:0 0 auto;width:var(--tile-size);height:var(--tile-size);
  display:inline-flex;align-items:center;justify-content:center;
  background:var(--tile);border:1px solid var(--tile-border);border-radius:14px;
  box-shadow:0 2px 0 var(--tile-shadow);
  font-size:calc(var(--tile-size) * .5);font-weight:800;color:var(--ink);
}
.op{
  flex:0 0 auto;height:var(--tile-size);min-width:calc(var(--tile-size) * .82);padding:0 6px;
  display:inline-flex;align-items:center;justify-content:center;border-radius:13px;
  background:var(--op);border:1px solid var(--tile-border);box-shadow:0 2px 0 var(--tile-shadow);
  font-size:calc(var(--tile-size) * .46);font-weight:800;color:var(--op-ink);cursor:pointer;
}
.op.eq{background:transparent;border-color:transparent;box-shadow:none;color:var(--ink);
  font-size:calc(var(--tile-size) * .52);min-width:calc(var(--tile-size) * .6);}
.op.paren{background:transparent;border-color:transparent;box-shadow:none;color:var(--muted);
  min-width:calc(var(--tile-size) * .42);padding:0 2px;font-size:calc(var(--tile-size) * .62);}

.gap{
  flex:0 0 auto;align-self:stretch;min-width:28px;
  display:inline-flex;align-items:center;justify-content:center;
  color:transparent;font-weight:800;border-radius:9px;cursor:pointer;
  transition:background .12s ease;
}
.board.arming .gap{color:#d9b673;background:#f8efdd;outline:1px dashed #e6cd96;}
.gap.drop-hover{color:var(--accent);background:#f2e6cf;outline:2px dashed var(--accent);}

.status{text-align:center;font-size:1rem;min-height:1.4em;color:var(--muted);font-weight:700;}
.status.ok{color:var(--good);}

/* palette */
.palette{display:flex;flex-wrap:wrap;gap:9px;justify-content:center;}
.ptile{
  width:var(--tile-size);height:var(--tile-size);
  display:flex;align-items:center;justify-content:center;
  background:var(--op);border:1px solid var(--tile-border);border-radius:14px;
  box-shadow:0 2px 0 var(--tile-shadow);position:relative;
  font-size:calc(var(--tile-size) * .46);font-weight:800;color:var(--op-ink);
  cursor:pointer;touch-action:none;
  transition:transform .08s ease,background .15s ease,box-shadow .12s ease;
}
.ptile:active{transform:translateY(1px);box-shadow:0 1px 0 var(--tile-shadow);}
.ptile.armed{background:var(--accent);color:var(--accent-ink);border-color:var(--accent);}
.ptile .pts{position:absolute;top:3px;right:5px;font-size:.6rem;font-weight:700;color:var(--muted);}
.ptile.armed .pts{color:var(--accent-ink);}

/* drag clone */
.clone{position:fixed;z-index:50;pointer-events:none;
  width:var(--tile-size);height:var(--tile-size);
  display:flex;align-items:center;justify-content:center;
  background:var(--accent);color:var(--accent-ink);border-radius:14px;
  font-size:calc(var(--tile-size) * .46);font-weight:800;
  box-shadow:0 6px 16px rgba(120,90,30,.35);transform:translate(-50%,-50%) scale(1.06);}

.actions{display:flex;gap:10px;}
.actions button{
  flex:1;padding:14px;border-radius:14px;border:1px solid var(--tile-border);
  background:var(--tile);color:var(--ink);font:inherit;font-weight:800;font-size:1rem;cursor:pointer;
  box-shadow:0 2px 0 var(--tile-shadow);}
.actions button:active{transform:translateY(1px);box-shadow:0 1px 0 var(--tile-shadow);}
#submit{background:var(--good);color:#fff;border-color:var(--good);}
#submit:disabled{background:var(--op);color:var(--muted);border-color:var(--tile-border);box-shadow:none;cursor:default;}

/* daily share CTA — dark to stand apart from the green Submit / light Clear */
.sharebtn{width:100%;padding:14px;border-radius:14px;border:none;
  background:var(--ink);color:var(--bg);font:inherit;font-weight:800;font-size:1rem;cursor:pointer;
  box-shadow:0 2px 0 var(--tile-shadow);}
.sharebtn:active{transform:translateY(1px);box-shadow:0 1px 0 var(--tile-shadow);}
.sharebtn[hidden]{display:none;}

.overlay{position:fixed;inset:0;background:rgba(244,243,238,.94);
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;
  padding:24px;text-align:center;z-index:100;}
.overlay[hidden]{display:none;}
.overlay h1{margin:0;font-size:1.6rem;font-weight:800;}
.overlay .big{font-size:3rem;font-weight:800;font-variant-numeric:tabular-nums;}
.overlay .sub{color:var(--muted);}
.overlay button{margin-top:14px;padding:14px 28px;border-radius:14px;border:none;
  background:var(--ink);color:var(--bg);font:inherit;font-weight:800;font-size:1.05rem;cursor:pointer;}

@media (prefers-reduced-motion: reduce){*{transition:none !important;}}
