/* ===========================================================
   PICHINKO — mobile-first neon theme
   =========================================================== */
:root {
  --bg: #0b0f1a;
  --bg-2: #121a2e;
  --panel: #161f36;
  --panel-2: #1d2842;
  --line: #243152;
  --text: #eaf0ff;
  --muted: #8595bd;
  --accent: #4af0c4;
  --accent-2: #6ea8ff;
  --gold: #ffd34e;
  --hot: #ff5d7a;
  --green: #46e08a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --r: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) 10px calc(var(--safe-bottom) + 8px);
  background:
    radial-gradient(120% 80% at 50% -10%, #1b2b4d 0%, transparent 60%),
    radial-gradient(100% 60% at 50% 110%, #16223f 0%, transparent 55%),
    linear-gradient(180deg, #0b0f1a 0%, #0a0d16 100%);
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 6px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px 12px;
  box-shadow: var(--shadow);
}
.stat-center { flex: 1; justify-content: center; }
.hud-right { display: flex; gap: 8px; align-items: stretch; margin-left: auto; }
.stat-icon {
  font-size: 15px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #aeb8cc 45%, #5c6680 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 5px rgba(180, 200, 240, .5));
}
.stat-body { display: flex; flex-direction: column; line-height: 1.1; align-items: center; }
.stat-label { font-size: 9px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
#balls-value { color: #dfe7f5; text-shadow: 0 0 16px rgba(150, 180, 230, .4); }
.stat-hero { padding: 6px 18px; }
.stat-hero .stat-value { font-size: 26px; }
.stat-best .stat-value { color: var(--accent-2); }
.stat-profit .stat-value { color: var(--muted); }
.stat-profit .stat-value.pos { color: var(--green); }
.stat-profit .stat-value.neg { color: var(--hot); }

.icon-btn {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  color: var(--text);
  width: 44px; border-radius: 14px;
  font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.muted { opacity: .5; }

/* ---------- Combo bar ---------- */
/* floats over the board — never reflows the game view */
#combo-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--safe-top) + 62px);
  width: min(80%, 300px);
  height: 22px;
  border-radius: 11px;
  background: rgba(10, 14, 24, .72);
  border: 1px solid var(--line);
  overflow: hidden;
  z-index: 25;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity .3s;
}
#combo-bar.hidden { opacity: 0; }
#combo-fill {
  position: absolute; inset: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--hot));
  transition: width .25s ease;
}
#combo-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}

/* ---------- Board ---------- */
#board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 2px 0 8px;
  border-radius: var(--r);
  overflow: hidden;
  background:
    linear-gradient(180deg, #11161f 0%, #0a0d13 100%);
  border: 1px solid #2a3344;
  box-shadow: var(--shadow), inset 0 0 60px rgba(0, 0, 0, .55);
}
#board { display: block; width: 100%; height: 100%; touch-action: none; }
#float-layer { position: absolute; inset: 0; pointer-events: none; }

/* ---------- Controls ---------- */
#controls { display: flex; flex-direction: column; gap: 8px; }
.control-row { display: flex; gap: 8px; align-items: stretch; }

.seg {
  display: flex; flex: 1;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 3px; gap: 3px;
}
.seg-btn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 13px; padding: 8px 0; border-radius: 9px;
  cursor: pointer; transition: .15s;
}
.seg-btn.active {
  background: linear-gradient(180deg, var(--accent-2), #3f7ad6);
  color: #06122b; box-shadow: 0 4px 14px rgba(110, 168, 255, .35);
}
.seg-btn:active { transform: scale(.96); }

.main-row { align-items: stretch; }
.drop-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; border: none; cursor: pointer;
  border-radius: 16px; padding: 12px;
  background: linear-gradient(180deg, var(--accent) 0%, #1fc79c 100%);
  color: #042018; box-shadow: 0 8px 22px rgba(74, 240, 196, .35), inset 0 1px 0 rgba(255, 255, 255, .4);
  transition: transform .08s;
}
.drop-btn:active { transform: translateY(2px) scale(.99); }
.drop-btn:disabled { filter: grayscale(.6) brightness(.7); box-shadow: none; }
.drop-main { font-size: 22px; font-weight: 900; letter-spacing: .08em; }
.drop-sub { font-size: 11px; font-weight: 700; opacity: .8; }

.stake-btn {
  width: 54px; border-radius: 16px; border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  color: var(--text); font-size: 26px; font-weight: 800; cursor: pointer;
  box-shadow: var(--shadow);
}
.stake-btn:active { transform: scale(.94); }

.ghost-btn {
  flex: 1; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
  font-weight: 700; font-size: 13px; padding: 10px 6px; border-radius: 12px; cursor: pointer;
}
.ghost-btn:active { transform: scale(.97); }
.ghost-btn.active { background: linear-gradient(180deg, var(--gold), #e0a91f); color: #2a1c00; border-color: transparent; }
.ghost-btn.danger { color: var(--hot); }
#ach-btn { color: var(--gold); }

/* ---------- Overlays / panels ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(5, 8, 16, .72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade .25s ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, var(--panel) 0%, #111a30 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px 22px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop .3s cubic-bezier(.2, 1.3, .5, 1);
}
@keyframes pop { from { transform: scale(.9) translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

.logo {
  margin: 0; font-size: 44px; font-weight: 900; letter-spacing: .04em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 20px rgba(74, 240, 196, .3));
}
.tagline { color: var(--muted); margin: 6px 0 22px; font-size: 14px; }
.fine { color: var(--muted); font-size: 11px; margin: 16px 0 0; }

.start-field { margin-bottom: 20px; }
.start-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .1em; }
.stepper, .stepper input, .stepper-btn { -webkit-appearance: none; }
.stepper { display: flex; gap: 8px; justify-content: center; align-items: center; }
.stepper-btn {
  width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 24px; font-weight: 800; cursor: pointer;
}
.stepper input {
  width: 90px; height: 46px; text-align: center; font-size: 22px; font-weight: 800;
  border-radius: 12px; border: 1px solid var(--line); background: #0d1424; color: var(--text);
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.cta {
  width: 100%; border: none; cursor: pointer;
  padding: 16px; border-radius: 16px; font-size: 18px; font-weight: 900; letter-spacing: .1em;
  background: linear-gradient(180deg, var(--accent), #1fc79c); color: #042018;
  box-shadow: 0 10px 26px rgba(74, 240, 196, .4);
}
.cta:active { transform: translateY(2px); }
.link-btn { margin-top: 14px; background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; text-decoration: underline; }

/* Buy panel */
.buy-emoji { font-size: 46px; }
.buy-panel h2 { margin: 6px 0 4px; font-size: 24px; }
.buy-panel p { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.buy-grid { display: flex; gap: 10px; }
.buy-card {
  position: relative; flex: 1; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  padding: 16px 6px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.buy-card.featured { border-color: var(--gold); background: linear-gradient(180deg, #2a2410, #1d2842); transform: scale(1.04); }
.buy-card:active { transform: scale(.97); }
.buy-amount { font-size: 22px; font-weight: 900; color: var(--accent); }
.buy-card.featured .buy-amount { color: var(--gold); }
.buy-price.free { font-size: 12px; font-weight: 800; color: var(--green); letter-spacing: .1em; }
.buy-badge {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: #2a1c00; font-size: 9px; font-weight: 900;
  padding: 2px 8px; border-radius: 20px; letter-spacing: .1em;
}

/* Settings */
.settings-panel h2 { margin: 0 0 18px; }
.toggle-row, .settings-field {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.toggle-row input { display: none; }
.switch { position: relative; width: 46px; height: 27px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line); transition: .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%; background: var(--muted); transition: .2s; }
.toggle-row input:checked ~ .switch { background: var(--accent); }
.toggle-row input:checked ~ .switch::after { transform: translateX(19px); background: #042018; }
.settings-field { border-bottom: none; }

/* ---------- Idle rate ---------- */
.idle-rate { font-size: 10px; font-weight: 800; color: var(--green); margin-top: 1px; }
.idle-rate.hidden { display: none; }

/* ---------- Tabbed menu ---------- */
.menu-panel { max-width: 420px; padding: 16px 14px 18px; text-align: left; }
.menu-tabs { display: flex; gap: 4px; background: #0d1424; border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.menu-tab { flex: 1; border: none; background: transparent; color: var(--muted); font-weight: 700; font-size: 13px; padding: 9px 4px; border-radius: 9px; cursor: pointer; }
.menu-tab.active { background: linear-gradient(180deg, var(--accent-2), #3f7ad6); color: #06122b; }
.menu-body { min-height: 290px; max-height: 56vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.menu-page.hidden { display: none; }
.menu-hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }

/* shop */
.shop-card { display: flex; align-items: center; gap: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.shop-icon { font-size: 26px; width: 36px; text-align: center; }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-weight: 800; font-size: 15px; }
.shop-name .lvl { color: var(--accent); font-size: 12px; margin-left: 6px; }
.shop-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.shop-buy { border: none; border-radius: 10px; padding: 9px 12px; font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap;
  background: linear-gradient(180deg, var(--accent), #1fc79c); color: #042018; }
.shop-buy:disabled { filter: grayscale(.7) brightness(.7); }
.shop-buy.max { background: var(--panel); color: var(--muted); }

/* achievements */
.ach { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 8px; background: var(--panel-2); }
.ach.locked { opacity: .45; filter: grayscale(.8); }
.ach-ico { font-size: 24px; width: 32px; text-align: center; }
.ach-name { font-weight: 800; font-size: 14px; }
.ach-desc { color: var(--muted); font-size: 12px; }

/* stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat-cell { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat-cell .k { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat-cell .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.fairness-out { white-space: pre-wrap; font-size: 11px; color: var(--accent); background: #0d1424; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 10px; max-height: 150px; overflow: auto; }
.fairness-out:empty { display: none; }

/* diagnostics overlay */
#diag { position: fixed; top: calc(var(--safe-top) + 4px); left: 4px; z-index: 80; font: 10px/1.4 monospace; color: #7dffce; background: rgba(0,0,0,.55); padding: 4px 7px; border-radius: 6px; pointer-events: none; white-space: pre; }
#diag.hidden { display: none; }

/* ---------- Calibration ---------- */
.calib-panel { text-align: center; }
.calib-panel h2 { margin: 14px 0 6px; font-size: 20px; }
.calib-panel p { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.spinner {
  width: 46px; height: 46px; margin: 0 auto; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.calib-bar { height: 8px; border-radius: 6px; background: rgba(255,255,255,.06); overflow: hidden; border: 1px solid var(--line); }
#calib-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .15s; }
#calib-pct { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Toasts ---------- */
#toast-layer {
  position: fixed; left: 0; right: 0; top: calc(var(--safe-top) + 70px); z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 30px;
  padding: 10px 18px; font-size: 14px; font-weight: 800; color: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in .3s cubic-bezier(.2, 1.3, .5, 1), toast-out .4s ease 1.7s forwards;
}
.toast.gold { border-color: var(--gold); color: var(--gold); }
.toast.hot { border-color: var(--hot); color: var(--hot); }
@keyframes toast-in { from { transform: translateY(-20px) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateY(-16px); opacity: 0; } }

/* Floating win text (DOM) */
.floatwin {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 900; font-size: 16px; pointer-events: none; white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .7);
  animation: floatup 1.1s ease-out forwards;
}
@keyframes floatup {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  20% { opacity: 1; transform: translate(-50%, -120%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -260%) scale(1); }
}

/* shake */
.shake { animation: shake .35s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

@media (min-height: 720px) {
  .stat-value { font-size: 20px; }
  .drop-main { font-size: 24px; }
}
