:root {
  --panel: rgba(8, 24, 36, 0.74);
  --panel-solid: #0d2433;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f1f7fa;
  --muted: #9fb8c6;
  --sea: #2fd6c5;
  --gold: #ffcc4d;
  --coral: #ff6b5a;
  --ok: #59d98e;
  --warn: #ffd23a;
  --bad: #ff4d4d;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b2230; color: var(--text);
  font-family: Inter, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
canvas { display: block; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.panel, .chip, #actions button {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud a { pointer-events: auto; }

#topbar { position: absolute; top: 14px; left: 14px; right: 260px; display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.brand {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: .01em;
}
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #9ff7ee, var(--sea)); box-shadow: 0 0 10px var(--sea); }
.chip { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.chip.balance b { font-size: 20px; font-variant-numeric: tabular-nums; color: var(--gold); }
.chip.balance small { color: var(--muted); }
.coin {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 13px;
  color: #3a2a00; background: radial-gradient(circle at 35% 30%, #fff0b3, var(--gold) 55%, #d39b12);
}
.chip.daily { flex-direction: column; align-items: stretch; gap: 4px; min-width: 230px; }
.daily-top, .daily-bottom { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); }
.daily-top b { color: var(--text); font-variant-numeric: tabular-nums; }
.daily-bottom { font-size: 11px; }
.bar { position: relative; height: 10px; border-radius: 6px; background: rgba(255,255,255,.1); overflow: hidden; }
#dailyFill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--sea), var(--gold)); border-radius: 6px; transition: width .3s; }
.chip.rod img { width: 30px; height: 30px; object-fit: contain; }
.chip.rod span { font-size: 13px; color: var(--muted); }

#actions { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
#actions button { color: var(--text); padding: 9px 12px; font-size: 13px; }
#actions button:hover { border-color: var(--sea); }

#message {
  position: absolute; top: 20%; left: 50%; transform: translateX(-50%); width: min(92vw, 760px);
  text-align: center; font-size: clamp(20px, 3.2vw, 32px); font-weight: 800; text-shadow: 0 2px 14px rgba(0,0,0,.55); transition: opacity .25s;
}
#message.big { color: var(--warn); font-size: clamp(34px, 6vw, 60px); }
#prompt {
  position: absolute; bottom: 132px; left: 50%; transform: translateX(-50%); padding: 8px 16px; border-radius: 999px;
  background: rgba(8, 24, 36, .62); font-size: 14px; white-space: nowrap; transition: opacity .2s;
}
#prompt:empty { opacity: 0; }
#prompt kbd { background: rgba(255,255,255,.14); border-radius: 6px; padding: 1px 7px; font-family: inherit; font-weight: 700; }

#meter { position: absolute; bottom: 58px; left: 50%; transform: translateX(-50%); width: min(90vw, 440px); padding: 12px 16px; }
#meter .top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#meter .top b { color: var(--text); }
#meter .bar { height: 16px; border-radius: 8px; }
#meterFill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ok); border-radius: 8px; }
#meterDanger { position: absolute; top: 0; bottom: 0; right: 0; width: 15%; background: repeating-linear-gradient(45deg, rgba(255,77,77,.35) 0 6px, transparent 6px 12px); }

#card { position: absolute; top: 50%; right: 5%; transform: translateY(-50%); width: min(86vw, 300px); padding: 18px 20px; text-align: center; }
#card .sp { font-size: 28px; font-weight: 800; }
#card .kg { font-size: 20px; margin-top: 4px; font-variant-numeric: tabular-nums; }
#card .reward { font-size: 26px; font-weight: 800; color: var(--gold); margin-top: 8px; }
#card .note { margin-top: 6px; color: var(--sea); font-weight: 700; min-height: 1.2em; font-size: 14px; }
#card .hint { margin-top: 12px; font-size: 12px; color: var(--muted); }

#journal { position: absolute; top: 96px; right: 14px; width: 270px; max-height: calc(100vh - 230px); overflow: auto; padding: 12px 14px; font-size: 13px; pointer-events: auto; }
#journal h3 { margin: 4px 0 8px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.jrow { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.jrow .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.jrow .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.jrow.unknown { color: #6f8796; }

/* Modals */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 10; background: rgba(4, 16, 24, .55); padding: 16px; }
.modal-box {
  width: min(96vw, 820px); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 18px; padding: 22px 24px; box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.modal-box.wide { width: min(96vw, 980px); }
.modal-box header { display: flex; align-items: center; gap: 14px; }
.modal-box h2 { margin: 0; font-size: 26px; }
.modal-box header .chip { margin-left: auto; }
.modal-box .sub { color: var(--muted); margin: 8px 0 16px; }
.close { background: none; border: 0; color: var(--muted); font-size: 28px; line-height: 1; padding: 0 4px; }
.close:hover { color: var(--text); }
.primary {
  background: linear-gradient(135deg, var(--sea), #19a6c7); color: #032430; border: 0; border-radius: 12px;
  padding: 12px 22px; font-weight: 800; font-size: 16px;
}
.primary:disabled { opacity: .45; cursor: default; }
.ghost { background: rgba(255,255,255,.06); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; font-weight: 700; }

#shopList { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.rodcard { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: rgba(255,255,255,.03); display: flex; flex-direction: column; gap: 8px; }
.rodcard.equipped { border-color: var(--sea); box-shadow: 0 0 0 1px var(--sea) inset; }
.rodcard .head { display: flex; gap: 10px; align-items: center; }
.rodcard img { width: 64px; height: 64px; object-fit: contain; background: rgba(255,255,255,.04); border-radius: 10px; }
.rodcard h4 { margin: 0; font-size: 16px; }
.rodcard .desc { font-size: 12px; color: var(--muted); }
.stat { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.stat .bar { height: 6px; }
.stat .bar div { position: absolute; inset: 0 auto 0 0; background: var(--sea); border-radius: 6px; }
.perks { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; }
.perks span { background: rgba(255, 204, 77, .12); color: var(--gold); border-radius: 999px; padding: 3px 8px; }
.rodcard .buy { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.price { font-weight: 800; color: var(--gold); }

#charList { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0 18px; }
.charcard {
  border: 2px solid var(--line); border-radius: 16px; padding: 10px 10px 14px; text-align: center;
  background: linear-gradient(180deg, rgba(47,214,197,.10), rgba(255,255,255,.02)); color: var(--text);
}
.charcard img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.charcard h4 { margin: 6px 0 2px; font-size: 18px; }
.charcard p { margin: 0; font-size: 12px; color: var(--muted); min-height: 2.6em; }
.charcard.selected { border-color: var(--sea); box-shadow: 0 0 24px rgba(47,214,197,.25); }
.select-foot { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
.controls { font-size: 12px; color: var(--muted); line-height: 1.6; }
.loadbar { height: 6px; background: rgba(255,255,255,.1); border-radius: 4px; overflow: hidden; }
#loadBar { height: 100%; width: 0; background: var(--sea); transition: width .2s; }

/* Touch controls */
#touch { position: absolute; inset: 0; pointer-events: none; }
#stick { position: absolute; left: 22px; bottom: 26px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.08); border: 1px solid var(--line); pointer-events: auto; touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: rgba(255,255,255,.25); }
#btnAction, #btnShopTouch {
  position: absolute; right: 24px; bottom: 34px; width: 96px; height: 96px; border-radius: 50%; border: 0;
  background: linear-gradient(135deg, var(--sea), #19a6c7); color: #032430; font-weight: 900; pointer-events: auto; touch-action: none;
}
#btnShopTouch { bottom: 146px; width: 70px; height: 70px; background: linear-gradient(135deg, var(--gold), #e8a51b); }

@media (max-width: 760px) {
  #topbar { right: 14px; top: 10px; gap: 6px; }
  .brand { display: none; }
  .chip.rod { display: none; }
  .chip.daily { min-width: 0; flex: 1; }
  #actions { top: auto; bottom: 170px; right: 10px; flex-direction: column; }
  #charList { grid-template-columns: repeat(2, 1fr); }
  .select-foot { flex-direction: column; align-items: stretch; }
  #card { right: 50%; transform: translate(50%, -50%); }
  #prompt { bottom: 150px; font-size: 12px; }
  #journal { top: auto; bottom: 140px; right: 10px; left: 10px; width: auto; max-height: 40vh; }
}
