/* ===================== THE SYSTEM — Solo Leveling UI ===================== */
:root {
  --bg:        #0a0e16;
  --bg-panel:  #0c121e;
  --bg-panel2: #0e1626;
  --cyan:      #38e1ff;
  --cyan-2:    #22d3ee;
  --cyan-dim:  #1c92a8;
  --line:      rgba(56, 225, 255, 0.30);
  --line-soft: rgba(56, 225, 255, 0.14);
  --text:      #d6eefc;
  --text-dim:  #7f9bb3;
  --glow:      0 0 12px rgba(56, 225, 255, 0.45);
  --glow-soft: 0 0 8px rgba(56, 225, 255, 0.20);
  --notch:     12px; /* corner cut */
}

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

/* the hidden attribute must always win, even over .overlay{display:flex} etc. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  /* radial vignette */
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(56,225,255,0.06), transparent 60%),
    var(--bg);
  /* room for fixed header + tabbar + notch */
  padding:
    calc(env(safe-area-inset-top) + 52px)
    env(safe-area-inset-right)
    calc(env(safe-area-inset-bottom) + 74px)
    env(safe-area-inset-left);
}

.mono { font-family: "SF Mono", ui-monospace, "Roboto Mono", Menlo, monospace; }

/* subtle scanline texture */
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: repeating-linear-gradient(
    to bottom, rgba(56,225,255,0.025) 0px, rgba(56,225,255,0.025) 1px,
    transparent 2px, transparent 4px);
  mix-blend-mode: screen; opacity: .5;
}

/* ===================== HEADER ===================== */
.sys-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(env(safe-area-inset-top) + 52px);
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(to bottom, rgba(10,14,22,0.96), rgba(10,14,22,0.78) 70%, transparent);
  backdrop-filter: blur(6px);
  letter-spacing: .42em;
}
.sys-header .sys-title {
  font-weight: 700; font-size: 15px; color: var(--cyan);
  text-shadow: var(--glow); padding-left: .42em;
}
.sys-header .bracket { color: var(--cyan-2); font-size: 18px; text-shadow: var(--glow); }

/* ===================== PANELS ===================== */
.view { display: none; padding: 14px 14px 4px; max-width: 540px; margin: 0 auto; position: relative; z-index: 2; }
.view.active { display: block; animation: viewIn .22s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

.panel {
  position: relative;
  background: linear-gradient(160deg, var(--bg-panel2), var(--bg-panel));
  border: 1px solid var(--line);
  box-shadow: var(--glow-soft), inset 0 0 28px rgba(56,225,255,0.04);
  padding: 16px;
  margin-bottom: 14px;
  /* notched corners */
  clip-path: polygon(
    var(--notch) 0, 100% 0, 100% calc(100% - var(--notch)),
    calc(100% - var(--notch)) 100%, 0 100%, 0 var(--notch));
}
/* corner accent ticks */
.panel::before, .panel::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  border-color: var(--cyan); pointer-events: none;
}
.panel::before { top: 6px; right: 6px; border-top: 2px solid; border-right: 2px solid; }
.panel::after  { bottom: 6px; left: 6px; border-bottom: 2px solid; border-left: 2px solid; }

.panel-head {
  font-size: 11px; letter-spacing: .28em; color: var(--cyan-2);
  text-transform: uppercase; margin-bottom: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}

/* ===================== RANK PANEL ===================== */
.rank-panel { padding-bottom: 18px; }
.rank-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.level-badge {
  flex: 0 0 auto; width: 74px; height: 74px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1.5px solid var(--cyan); box-shadow: var(--glow), inset 0 0 14px rgba(56,225,255,0.12);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: rgba(56,225,255,0.05);
}
.level-label { font-size: 8px; letter-spacing: .2em; color: var(--text-dim); }
.level-num { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 32px; font-weight: 700; color: var(--cyan); text-shadow: var(--glow); line-height: 1; }
.rank-info { min-width: 0; }
.rank-title { font-size: 19px; font-weight: 700; color: var(--text); letter-spacing: .01em; }
.total-xp { font-family: "SF Mono", ui-monospace, Menlo, monospace; color: var(--text-dim); font-size: 14px; margin-top: 4px; }
.total-xp span { color: var(--cyan-2); }

.xpbar {
  position: relative; height: 22px; border: 1px solid var(--line);
  background: rgba(0,0,0,0.35); overflow: hidden;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.xpbar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--cyan-dim), var(--cyan));
  box-shadow: 0 0 14px rgba(56,225,255,0.6);
  transition: width .6s cubic-bezier(.2,.8,.2,1);
}
.xpbar-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 11px; letter-spacing: .08em;
  color: var(--text); text-shadow: 0 1px 2px #000;
}

/* ===================== STATS ===================== */
.stats-grid { display: grid; gap: 12px; }
.stat-row { display: grid; grid-template-columns: 42px 1fr 38px; align-items: center; gap: 10px; }
.stat-key { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--cyan-2); }
.stat-val { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 16px; text-align: right; color: var(--text); }
.stat-track { height: 10px; background: rgba(0,0,0,0.4); border: 1px solid var(--line-soft); position: relative; }
.stat-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--cyan-dim), var(--cyan)); box-shadow: 0 0 8px rgba(56,225,255,0.4); transition: width .6s cubic-bezier(.2,.8,.2,1); }

/* ===================== QUEST ===================== */
.quest-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; margin-top: -4px; }
.quest-cleared {
  font-size: 10px; letter-spacing: .18em; color: var(--bg); background: var(--cyan);
  padding: 3px 8px; border-radius: 2px; box-shadow: var(--glow); opacity: 0;
  transform: scale(.8); transition: opacity .3s, transform .3s;
}
.quest-panel.cleared .quest-cleared { opacity: 1; transform: scale(1); }
.quest-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.quest-list li { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text-dim); }
.q-check {
  flex: 0 0 auto; width: 22px; height: 22px; border: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; color: var(--cyan);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
  transition: all .2s;
}
.quest-list li.done { color: var(--text); }
.quest-list li.done .q-check { background: rgba(56,225,255,0.14); border-color: var(--cyan); box-shadow: var(--glow-soft); }
.quest-list li.done .q-check::after { content: "✓"; font-weight: 700; }
.q-text em { font-style: normal; color: var(--text-dim); font-size: 12px; }

/* ===================== BIG ACTION ===================== */
.big-action {
  width: 100%; padding: 16px; margin-top: 2px; font-size: 15px; font-weight: 700;
  letter-spacing: .2em; color: var(--bg); background: linear-gradient(120deg, var(--cyan-2), var(--cyan));
  border: none; box-shadow: var(--glow); cursor: pointer;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.big-action:active { transform: translateY(1px) scale(.995); }

/* ===================== QUICK LOG ===================== */
.log-grid { display: grid; gap: 12px; }
.log-card {
  border: 1px solid var(--line-soft); background: rgba(0,0,0,0.22); padding: 12px 12px 14px;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.log-card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.log-name { font-size: 15px; font-weight: 700; color: var(--text); }
.log-xprate { font-size: 11px; color: var(--text-dim); font-family: "SF Mono", ui-monospace, Menlo, monospace; }
.log-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.preset {
  flex: 1 1 auto; min-width: 56px; padding: 12px 6px; font-size: 14px; font-weight: 700;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  background: rgba(56,225,255,0.07); color: var(--cyan); border: 1px solid var(--line);
  cursor: pointer; clip-path: polygon(5px 0,100% 0,100% calc(100% - 5px),calc(100% - 5px) 100%,0 100%,0 5px);
}
.preset:active { background: rgba(56,225,255,0.2); transform: translateY(1px); }
.preset.unit { color: var(--text-dim); font-size: 11px; flex: 0 0 auto; min-width: 0; background: transparent; border-color: var(--line-soft); cursor: default; }
.preset.unit:active { transform: none; background: transparent; }

/* custom stepper */
.stepper { display: flex; align-items: stretch; gap: 0; flex: 1 1 100%; margin-top: 2px; }
.stepper button.step {
  width: 46px; font-size: 22px; font-weight: 700; color: var(--cyan);
  background: rgba(56,225,255,0.07); border: 1px solid var(--line); cursor: pointer;
}
.stepper button.step:active { background: rgba(56,225,255,0.2); }
.stepper input {
  flex: 1; text-align: center; font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 18px; background: rgba(0,0,0,0.4); color: var(--text);
  border: 1px solid var(--line); border-left: none; border-right: none; min-width: 0;
}
.stepper .add {
  padding: 0 16px; font-size: 13px; font-weight: 700; letter-spacing: .1em; color: var(--bg);
  background: linear-gradient(120deg,var(--cyan-2),var(--cyan)); border: none; cursor: pointer;
}
.stepper .add:active { transform: translateY(1px); }

/* ===================== HISTORY ===================== */
.history-list { display: grid; gap: 10px; }
.hist-day {
  border: 1px solid var(--line-soft); background: rgba(0,0,0,0.22); padding: 12px;
  clip-path: polygon(8px 0,100% 0,100% calc(100% - 8px),calc(100% - 8px) 100%,0 100%,0 8px);
}
.hist-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.hist-date { font-size: 14px; font-weight: 700; color: var(--text); }
.hist-xp { font-family: "SF Mono", ui-monospace, Menlo, monospace; color: var(--cyan-2); font-size: 14px; }
.hist-entries { font-size: 13px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; }
.hist-boss { margin-top: 8px; font-size: 12px; color: var(--cyan); display: flex; align-items: center; gap: 6px; }
.hist-cleared { color: var(--cyan); font-size: 10px; letter-spacing: .12em; border: 1px solid var(--line); padding: 1px 6px; margin-left: 6px; }
.empty { color: var(--text-dim); text-align: center; padding: 40px 10px; font-size: 14px; }

/* ===================== BACKUP / BUTTONS ===================== */
.backup-copy { font-size: 13px; color: var(--text-dim); line-height: 1.55; margin: 0 0 14px; }
.action-btn {
  width: 100%; padding: 14px; margin-bottom: 10px; font-size: 14px; font-weight: 700; letter-spacing: .12em;
  color: var(--cyan); background: rgba(56,225,255,0.07); border: 1px solid var(--cyan); cursor: pointer;
  clip-path: polygon(8px 0,100% 0,100% calc(100% - 8px),calc(100% - 8px) 100%,0 100%,0 8px);
}
.action-btn:active { background: rgba(56,225,255,0.2); transform: translateY(1px); }
.action-btn.ghost { color: var(--text-dim); border-color: var(--line); background: transparent; }
.backup-meta { font-size: 12px; color: var(--text-dim); font-family: "SF Mono", ui-monospace, Menlo, monospace; margin-top: 4px; line-height: 1.5; }
.hint-text { text-align: center; font-size: 12px; color: var(--text-dim); margin: 6px 0 4px; }

/* ===================== TABBAR ===================== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(to top, rgba(10,14,22,0.98), rgba(10,14,22,0.86));
  border-top: 1px solid var(--line); backdrop-filter: blur(8px);
}
.tab {
  flex: 1; padding: 10px 2px 8px; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 9px; letter-spacing: .14em; color: var(--text-dim); font-weight: 700;
}
.tab span { font-size: 18px; line-height: 1; }
.tab.active { color: var(--cyan); text-shadow: var(--glow-soft); }
.tab.active span { filter: drop-shadow(var(--glow-soft)); }

/* ===================== OVERLAYS ===================== */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 28px;
  background: rgba(4,7,12,0.86); backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.boss-card, .levelup-inner {
  width: 100%; max-width: 420px; text-align: center; padding: 28px 22px;
  border: 1.5px solid var(--cyan); background: linear-gradient(160deg, var(--bg-panel2), var(--bg-panel));
  box-shadow: var(--glow), inset 0 0 40px rgba(56,225,255,0.06);
  clip-path: polygon(16px 0,100% 0,100% calc(100% - 16px),calc(100% - 16px) 100%,0 100%,0 16px);
}
.boss-tag { font-size: 12px; letter-spacing: .26em; color: var(--cyan); text-shadow: var(--glow); margin-bottom: 10px; }
.boss-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.boss-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 20px; }
.stamina-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.stamina-row button {
  width: 52px; height: 56px; font-size: 22px; font-weight: 700; font-family: "SF Mono", ui-monospace, Menlo, monospace;
  color: var(--cyan); background: rgba(56,225,255,0.07); border: 1px solid var(--cyan); cursor: pointer;
  clip-path: polygon(6px 0,100% 0,100% calc(100% - 6px),calc(100% - 6px) 100%,0 100%,0 6px);
}
.stamina-row button:active { background: var(--cyan); color: var(--bg); }
.stamina-legend { font-size: 11px; color: var(--text-dim); }

/* level up */
.levelup { background: rgba(4,7,12,0.92); }
.levelup-inner { animation: luPop .5s cubic-bezier(.2,1.2,.3,1); }
@keyframes luPop { 0% { transform: scale(.7); opacity: 0; } 60% { transform: scale(1.04); } 100% { transform: scale(1); opacity: 1; } }
.lu-bracket { font-size: 16px; letter-spacing: .3em; color: var(--cyan); text-shadow: var(--glow); margin-bottom: 16px; animation: pulse 1.4s ease-in-out infinite; }
.lu-level { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 18px; color: var(--text-dim); letter-spacing: .2em; }
.lu-level span { color: var(--cyan); font-size: 30px; }
.lu-title { font-size: 30px; font-weight: 700; color: var(--text); margin: 8px 0 4px; text-shadow: var(--glow-soft); }
.lu-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 22px; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ===================== TOASTS ===================== */
.toast-wrap {
  position: fixed; left: 0; right: 0; z-index: 50;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  font-family: "SF Mono", ui-monospace, Menlo, monospace; font-weight: 700; font-size: 15px;
  color: var(--cyan); background: rgba(10,14,22,0.92); border: 1px solid var(--cyan);
  padding: 9px 18px; box-shadow: var(--glow);
  clip-path: polygon(8px 0,100% 0,100% calc(100% - 8px),calc(100% - 8px) 100%,0 100%,0 8px);
  animation: toastIn .25s ease, toastOut .35s ease 1.3s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

/* ===================== iOS HINT ===================== */
.ios-hint {
  position: fixed; left: 12px; right: 12px; z-index: 55;
  bottom: calc(env(safe-area-inset-bottom) + 82px);
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: rgba(12,18,30,0.97); border: 1px solid var(--cyan); box-shadow: var(--glow);
  padding: 12px 14px; font-size: 13px; color: var(--text);
  clip-path: polygon(8px 0,100% 0,100% calc(100% - 8px),calc(100% - 8px) 100%,0 100%,0 8px);
}
.ios-hint b { color: var(--cyan); }
.ios-hint button { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 0 4px; }

/* ===================== REDUCED MOTION ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
  .xpbar-fill, .stat-bar { transition: width .001s !important; }
}
