:root {
  --gold: #e3c27a;
  --gold-2: #b8913f;
  --ink: #f6eedc;
  --muted: rgba(246, 238, 220, 0.66);
  --panel: rgba(12, 22, 17, 0.82);
  --line: rgba(227, 194, 122, 0.38);
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0b2c1d; color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
canvas { position: fixed; left: 0; top: 0; display: block; }
#table { touch-action: none; }
#fx { pointer-events: none; }
.hidden { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---- HUD ---------------------------------------------------------------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
  height: calc(52px + env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(0,0,0,0.5), rgba(0,0,0,0.18));
  border-bottom: 1px solid rgba(227,194,122,0.18);
}
.hud-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.hud-title { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hud-title span { font-family: var(--serif); font-size: 17px; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-title small { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; white-space: nowrap; }
.hud-stats { display: flex; gap: 16px; flex: 0 0 auto; }
.hud-stats div { display: flex; flex-direction: column; align-items: center; line-height: 1.05; min-width: 44px; }
.hud-stats small { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.hud-stats b { font-family: var(--serif); font-size: 18px; font-variant-numeric: tabular-nums; }
.ibtn {
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12);
}
.ibtn:hover { background: rgba(255,255,255,0.14); }

#toolbar { display: flex; gap: 6px; flex: 0 0 auto; }
.tbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-width: 56px; height: 40px; padding: 0 10px; border-radius: 10px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12);
  font-size: 11px; letter-spacing: 0.04em; transition: background .15s, transform .1s;
}
.tbtn .ic { font-size: 16px; line-height: 1; }
.tbtn:hover { background: rgba(255,255,255,0.15); }
.tbtn:active { transform: scale(0.95); }
.tbtn:disabled { opacity: 0.4; cursor: default; }
.tbtn.gold { background: linear-gradient(180deg, #f1d58e, #b98d34); color: #2a1a05; border-color: #f6e2a8; animation: glow 1.4s ease-in-out infinite; }
.tbtn.off .ic { opacity: 0.4; text-decoration: line-through; }
@keyframes glow { 50% { box-shadow: 0 0 18px rgba(241,213,142,0.7); } }

@media (max-width: 760px) {
  #hud { gap: 8px; padding-left: 8px; padding-right: 8px; height: calc(48px + env(safe-area-inset-top)); }
  .hud-stats { gap: 8px; }
  .hud-stats b { font-size: 16px; }
  .hud-stats div { min-width: 38px; }
  #toolbar {
    position: fixed; left: 0; right: 0; bottom: 0; justify-content: space-around;
    padding: 6px 8px max(6px, env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(0,0,0,0.55), rgba(0,0,0,0.25));
    border-top: 1px solid rgba(227,194,122,0.18);
  }
  .tbtn { flex: 1 1 0; max-width: 90px; height: 44px; }
}
@media (max-width: 380px) {
  .hud-title small { display: none; }
}

/* ---- toast -------------------------------------------------------------- */
#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 20px); z-index: 20;
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  background: rgba(10,18,14,0.9); border: 1px solid var(--line); color: var(--ink);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; white-space: nowrap;
  max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- screens ------------------------------------------------------------ */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.25), rgba(0,0,0,0.6));
  animation: fade .25s ease-out;
}
#scrTitle { background: radial-gradient(ellipse at 50% 30%, rgba(0,0,0,0.05), rgba(0,0,0,0.45)); align-items: flex-start; padding-top: max(16px, 4vh); }
@keyframes fade { from { opacity: 0; } }
.panel {
  width: min(520px, 100%); margin: auto;
  padding: 26px 26px 20px; border-radius: 22px;
  background: linear-gradient(180deg, rgba(16,30,23,0.9), rgba(8,16,12,0.92));
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.06);
  text-align: center;
  animation: rise .35s cubic-bezier(.2,.9,.3,1.2);
}
.panel.small { width: min(380px, 100%); }
@keyframes rise { from { transform: translateY(18px) scale(0.97); opacity: 0; } }
.crest { color: var(--gold); letter-spacing: 0.5em; font-size: 14px; opacity: 0.85; margin-left: 0.5em; }
h1 {
  font-family: var(--serif); font-weight: 400; margin: 6px 0 2px;
  font-size: clamp(36px, 9vw, 56px); line-height: 1;
  background: linear-gradient(180deg, #fff3cf 0%, #e3c27a 45%, #a77b2a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 2px 0 rgba(0,0,0,0.0);
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.5));
}
h1 em { font-style: italic; }
h2 { font-family: var(--serif); font-weight: 400; color: var(--gold); font-size: 32px; margin: 4px 0 6px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.tag { font-family: var(--serif); font-style: italic; color: var(--muted); margin: 6px 0 18px; }
.sub { color: var(--muted); margin: 4px 0 12px; font-size: 14px; }
.note { color: var(--muted); font-size: 14px; margin: 4px 0; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.08); }
.tab { flex: 1; padding: 10px 6px; border-radius: 10px; font-family: var(--serif); font-size: 17px; color: var(--muted); transition: background .15s, color .15s; }
.tab.on { background: linear-gradient(180deg, rgba(227,194,122,0.28), rgba(227,194,122,0.12)); color: #fff4d6; box-shadow: inset 0 0 0 1px rgba(227,194,122,0.45); }
.opts { margin: 14px 0 4px; display: flex; flex-direction: column; gap: 8px; align-items: center; min-height: 40px; }
.seg { display: inline-flex; align-items: center; gap: 4px; padding: 3px; border-radius: 12px; background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.08); }
.seg > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); padding: 0 8px 0 10px; min-width: 64px; text-align: left; }
.seg button { padding: 7px 12px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: rgba(227,194,122,0.22); color: #fff4d6; }

.actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.btn {
  padding: 12px 22px; border-radius: 14px; font-size: 16px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.15);
  transition: transform .1s, background .15s, box-shadow .15s;
}
.btn:hover { background: rgba(255,255,255,0.13); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  min-width: 170px; font-family: var(--serif); font-size: 20px; letter-spacing: 0.03em;
  background: linear-gradient(180deg, #f4dc9c, #c99a3f 60%, #a77b2a); color: #2a1a05;
  border-color: #f8e7b5; box-shadow: 0 8px 24px rgba(201,154,63,0.35), inset 0 1px 0 rgba(255,255,255,0.6);
}
.btn.primary:hover { box-shadow: 0 10px 30px rgba(201,154,63,0.55), inset 0 1px 0 rgba(255,255,255,0.6); }
.btn.ghost { background: none; color: var(--muted); }

.daily {
  margin: 16px auto 0; display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border-radius: 14px; text-align: left;
  background: linear-gradient(90deg, rgba(227,194,122,0.14), rgba(227,194,122,0.04));
  border: 1px solid var(--line);
}
.daily:hover { background: linear-gradient(90deg, rgba(227,194,122,0.22), rgba(227,194,122,0.08)); }
.daily .sun { font-size: 24px; color: var(--gold); }
.daily > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.daily small { color: var(--muted); font-size: 12px; }
#dailyMark { font-size: 13px; color: var(--gold); white-space: nowrap; }
.statline { margin-top: 14px; font-size: 13px; color: var(--muted); min-height: 18px; }
.links { display: flex; gap: 18px; justify-content: center; margin-top: 10px; }
.link { color: var(--gold); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(227,194,122,0.4); }
.controls { font-size: 11.5px; color: rgba(246,238,220,0.5); margin: 14px 0 0; line-height: 1.6; }

.winstats { display: flex; justify-content: center; gap: 26px; margin: 12px 0 6px; }
.winstats div { display: flex; flex-direction: column; }
.winstats small { font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }
.winstats b { font-family: var(--serif); font-size: 28px; color: #fff4d6; font-variant-numeric: tabular-nums; }
.badges { min-height: 22px; margin: 6px 0; }
.badge { display: inline-block; margin: 3px; padding: 4px 10px; border-radius: 999px; font-size: 12px; background: rgba(227,194,122,0.2); border: 1px solid var(--line); color: #fff1c9; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.sw {
  width: 76px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
  padding: 6px 4px; border-radius: 12px; border: 1px solid transparent;
}
.sw.on { border-color: var(--gold); color: #fff4d6; background: rgba(227,194,122,0.1); }
.sw.locked { opacity: 0.45; cursor: not-allowed; }
.sw i { display: block; width: 52px; height: 52px; border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15), 0 4px 10px rgba(0,0,0,0.4); }
.sw canvas { position: static; width: 44px; height: 62px; border-radius: 5px; box-shadow: 0 4px 10px rgba(0,0,0,0.4); }
.how { text-align: left; font-size: 14px; line-height: 1.55; color: rgba(246,238,220,0.86); }
.how p { margin: 0 0 10px; }
.how b { color: var(--gold); font-family: var(--serif); font-weight: 400; font-size: 15px; }

@media (max-height: 640px) {
  .panel { padding: 18px 18px 14px; }
  h1 { font-size: 36px; }
  .tag { margin-bottom: 10px; }
  .controls { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .panel, .tbtn.gold { animation: none; }
}
