/* ============================================================
   Study Factory — styles
   Pixel-art / retro-game pop theme, light + dark, responsive
   ============================================================ */

/* ---- Pixel font (DotGothic16 = Japanese dot font, loaded in <head>) ---- */
:root {
  --font-pixel: "DotGothic16", "Press Start 2P", ui-monospace, "Courier New", monospace;
  --font-ui: "DotGothic16", system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;

  /* spacing / radius */
  --gap: 12px;
  --radius: 10px;
  --tabbar-h: 64px;

  /* ---- Olive monochrome (image-accurate, default look) ---- */
  --bg: #777a60;            /* muted olive page */
  --bg-panel: #5e6248;      /* panel olive */
  --bg-panel-2: #525541;    /* inset / darker olive */
  --text: #e9eada;          /* light khaki text */
  --text-dim: #bcbda2;      /* dimmed khaki */
  --border: #3a3d2d;        /* dark olive border */
  --accent: #d7dab8;        /* light highlight (coins / progress) */
  --accent-2: #b9bc9c;      /* secondary highlight */
  --good: #aab491;
  --bad: #c79a86;
  --glow: rgba(231,234,200,.30);
  --shadow: 0 4px 0 rgba(0,0,0,0.30);
}

body[data-theme="dark"] {
  --bg: #2f3327;
  --bg-panel: #3b3f30;
  --bg-panel-2: #2a2e22;
  --text: #e3e4d2;
  --text-dim: #9fa088;
  --border: #1f2218;
  --accent: #c7caa8;
  --accent-2: #9a9d80;
  --good: #97a079;
  --bad: #b78c78;
  --glow: rgba(199,202,168,.28);
  --shadow: 0 4px 0 rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
  overscroll-behavior-y: none;
}

/* pixel-art: keep edges crisp on any SVG/image set to this class */
.pixelated { image-rendering: pixelated; image-rendering: crisp-edges; }

/* pixel icons (icons.js) inherit currentColor and align with text */
.pico { display: inline-block; vertical-align: -0.18em; }
.pico rect { shape-rendering: crispEdges; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
}

/* ---- Screens ---- */
#screens {
  flex: 1;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px) 16px;
}
.screen[hidden] { display: none; }
.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to {opacity:1; transform:none;} }

/* ---- Bottom tab bar ---- */
#tabbar {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 720px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg-panel);
  border-top: 2px solid var(--border);
  z-index: 50;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim);
  font-size: 11px; font-family: var(--font-ui);
  transition: color .15s, transform .1s;
}
.tab .tab-ico { font-size: 22px; line-height: 1; display: flex; }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"] .tab-ico { transform: translateY(-2px) scale(1.1); filter: drop-shadow(0 0 6px var(--glow)); }
.tab:active { transform: scale(.94); }

/* ---- Common building blocks ---- */
.panel {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: var(--gap); }

h1, h2, h3 { font-family: var(--font-pixel); margin: 0 0 .5em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }

.btn {
  font-family: var(--font-pixel);
  font-size: 13px;
  letter-spacing: 1px;
  border: 2px solid var(--text-dim);
  border-radius: 10px;
  padding: 12px 18px;
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 0 14px var(--glow), 0 4px 0 rgba(0,0,0,.30);
  transition: transform .08s, box-shadow .08s, filter .1s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 0 8px var(--glow), 0 1px 0 rgba(0,0,0,.30); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: 0 4px 0 rgba(0,0,0,.30); }
.btn.secondary { background: var(--bg-panel-2); color: var(--text); border-color: var(--border); box-shadow: 0 4px 0 rgba(0,0,0,.30); }
.btn.danger { background: var(--bg-panel-2); color: var(--bad); border-color: var(--bad); box-shadow: 0 4px 0 rgba(0,0,0,.30); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-dim); box-shadow: none; }
.btn.block { width: 100%; }

.row { display: flex; gap: var(--gap); align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

input, select {
  font-family: var(--font-ui);
  font-size: 15px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-panel-2);
  color: var(--text);
}

/* ---- Toggle switch ---- */
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 30px; transition: .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 22px; width: 22px; left: 4px; top: 4px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--good); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ============================================================
   Modal / overlay
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,12,24,.55); padding: 20px;
  animation: fade .2s ease;
}
.modal {
  background: var(--bg-panel);
  border: 3px solid var(--text);
  border-radius: 16px;
  padding: 22px;
  width: 100%; max-width: 420px;
  box-shadow: 0 8px 0 rgba(0,0,0,.3);
  animation: pop .25s cubic-bezier(.2,1.4,.5,1);
}
@keyframes pop { from { transform: scale(.8); opacity:0;} to {transform:scale(1); opacity:1;} }
.modal h2 { text-align: center; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions .btn { flex: 1; }

/* onboarding slides */
.ob-slide { text-align: center; }
.ob-art { font-size: 56px; margin: 6px 0 12px; }
.ob-dots { display: flex; gap: 8px; justify-content: center; margin: 16px 0 4px; }
.ob-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.ob-dots i.on { background: var(--accent-2); }

/* ============================================================
   Timer screen
   ============================================================ */
.seg {
  display: flex; background: var(--bg-panel-2);
  border: 2px solid var(--border); border-radius: 12px; padding: 3px; gap: 3px;
}
.seg.small { flex: none; }
.seg-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  font-family: var(--font-pixel); font-size: 12px; color: var(--text-dim);
  padding: 9px 12px; border-radius: 9px; transition: .15s; white-space: nowrap;
}
.seg.small .seg-btn { font-size: 10px; padding: 8px 10px; }
.seg-btn.on { background: var(--accent); color: #2f3327; }
.seg-btn:disabled { opacity: .5; cursor: not-allowed; }

.factory-stage {
  margin: 6px 0 12px;
  border: 2px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg-panel-2);
  min-height: 200px; height: 240px; display: block;
  position: relative;
}
.view-toggle {
  position: absolute; right: 8px; bottom: 8px; z-index: 5;
  font-size: 11px; padding: 8px 12px;
}

.timer-panel { padding-top: 18px; }
.phase-label {
  font-family: var(--font-pixel); font-size: 13px; margin-bottom: 4px;
  color: var(--text-dim);
}
.phase-label[data-phase="study"] { color: var(--good); }
.phase-label[data-phase="break"], .phase-label[data-phase="long"] { color: var(--accent-2); }
.time-big {
  font-family: var(--font-pixel);
  font-size: clamp(44px, 14vw, 68px);
  line-height: 1.1; letter-spacing: 1px;
}
.coin-row { display: flex; gap: 10px; justify-content: center; align-items: center; margin: 10px 0 6px; }
.coin-chip { font-size: 18px; color: var(--accent); display: inline-flex; align-items: center; gap: 5px; }
.coin-chip b { font-family: var(--font-pixel); color: var(--accent); }
.progress {
  height: 10px; background: var(--bg-panel-2); border: 2px solid var(--border);
  border-radius: 20px; overflow: hidden; margin: 4px auto 0; max-width: 280px;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .4s;
}

/* ============================================================
   Settings screen
   ============================================================ */
.set-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
.pomo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pomo-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.pomo-grid input { width: 100%; }

/* ============================================================
   Stats screen
   ============================================================ */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-cell {
  background: var(--bg-panel-2); border: 2px solid var(--border);
  border-radius: 10px; padding: 12px; text-align: center;
}
.stat-cell .muted { font-size: 12px; }
.stat-cell b { font-family: var(--font-pixel); font-size: 16px; display: block; margin-top: 4px; }
.chart-box { max-width: 320px; margin: 8px auto 0; }

/* ============================================================
   Subjects screen
   ============================================================ */
.factory-stage.big { min-height: 220px; }
.subj-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 2px solid var(--border); border-radius: 12px;
  background: var(--bg-panel-2); margin-bottom: 10px;
}
.subj-item.selected { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2) inset; }
.subj-ico { position: relative; font-size: 34px; flex: none; width: 48px; text-align: center; }
.subj-lv {
  position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-pixel); font-size: 9px; background: var(--text); color: var(--bg);
  padding: 1px 4px; border-radius: 6px; white-space: nowrap;
}
.subj-main { flex: 1; min-width: 0; }
.subj-name { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.subj-time { font-size: 13px; margin-top: 2px; }
.subj-actions { display: flex; flex-direction: column; gap: 4px; }
.icon-btn {
  border: none; background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-size: 15px; padding: 5px 7px; line-height: 1;
}
.icon-btn:active { transform: scale(.9); }
.subj-ico { cursor: pointer; }

/* ============================================================
   Upgrade menu (factory strengthening)
   ============================================================ */
.up-balance { text-align: center; color: var(--accent); font-size: 18px; margin: 2px 0 14px; }
.up-balance .muted { font-size: 12px; }
.up-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-panel-2); border: 2px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
.up-main { flex: 1; min-width: 0; }
.up-name { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.up-eff { font-size: 12px; margin-top: 2px; }
.up-buy {
  flex: none; font-family: var(--font-pixel); font-size: 12px;
  padding: 8px 10px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}

/* ============================================================
   Level-up celebration
   ============================================================ */
.levelup { text-align: center; position: relative; }
.levelup-art { font-size: 52px; animation: pop .4s; }
.levelup-badge {
  font-family: var(--font-pixel); font-size: 26px; color: var(--accent);
  margin: 6px 0;
}
.levelup-burst { position: absolute; top: 30px; left: 50%; width: 0; height: 0; }
.coin-particle {
  position: absolute; font-size: 20px; color: var(--accent); left: 0; top: 0;
  animation: coinfly .9s ease-out forwards;
}
@keyframes coinfly {
  0% { transform: translate(0,0) scale(.4); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1); opacity: 0; }
}

/* utility */
.muted { color: var(--text-dim); }
.center { text-align: center; }
.big-num { font-family: var(--font-pixel); font-size: 34px; color: var(--accent); }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--bg-panel-2); border:1px solid var(--border); }

/* ============================================================
   Customization shop + countdown timer UI
   ============================================================ */
.cd-row { justify-content: center; gap: 6px; margin: 10px 0 0; flex-wrap: wrap; }
.cd-row input[type="number"] {
  width: 72px; text-align: center;
  background: var(--bg-panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px;
  font-family: var(--font-pixel);
}

.chip {
  font-family: var(--font-pixel); font-size: 12px; line-height: 1.3;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
  background: var(--bg-panel-2); color: var(--text);
  border: 1px solid var(--border);
  display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
}
.chip.on {
  background: var(--accent); color: var(--bg-deep, #1f2218);
  border-color: var(--accent);
}
.chip.locked { opacity: .55; cursor: not-allowed; }
.chip:disabled { cursor: default; }
.chip-sub { font-size: 10px; opacity: .8; display: inline-flex; align-items: center; gap: 3px; }

.shop-tabs { margin: 10px 0; display: flex; }
.shop-tabs .seg-btn { flex: 1; }
.shop-body { max-height: 46vh; overflow-y: auto; padding-right: 2px; }
.shop-slot { padding: 10px 0; border-bottom: 1px dashed var(--border); }
.shop-slot:last-child { border-bottom: none; }
.shop-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.rate-chip {
  font-family: var(--font-pixel); font-size: 12px;
  padding: 4px 8px; border-radius: 8px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  color: var(--accent);
}

/* shop header row: balance left, live rate right */
.up-balance { display: flex; align-items: center; justify-content: center; gap: 6px; }

/* achievements list (stats screen) */
.ach-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.ach-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  opacity: .55;
}
.ach-row.got { opacity: 1; }
.ach-row.got .ach-star { color: var(--accent); }
.ach-star { font-size: 16px; }
.ach-name { flex: 1; font-size: 13px; }

/* ============================================================
   Fullscreen factory + HUD / calendar / EX
   ============================================================ */
.fs-toggle {
  position: absolute; right: 8px; top: 8px; z-index: 5;
  font-size: 11px; padding: 8px 12px;
}
/* self-managed "fullscreen" — a fixed overlay rather than the real
   Fullscreen API, so nothing outside a user tap (permission prompts,
   in-app browsers like LINE's, iOS Safari) can force it closed */
.factory-stage.pseudo-fs {
  position: fixed; inset: 0; z-index: 60;
  width: 100vw; height: 100vh;
  margin: 0; border: none; border-radius: 0;
}
.fs-hud { display: none; }
.factory-stage.pseudo-fs .fs-hud {
  display: block; position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  text-align: center; pointer-events: none; z-index: 4;
  text-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.fs-hud #fsClock { font-family: var(--font-pixel); font-size: 56px; color: var(--text); }
.fs-hud #fsPhase { font-family: var(--font-pixel); font-size: 14px; color: var(--accent); }
.fs-hud-actions { pointer-events: auto; display: flex; gap: 28px; justify-content: center; margin-top: 14px; }

/* calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-dim); font-family: var(--font-pixel); padding: 2px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 8px; position: relative; cursor: pointer;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.cal-day.empty { background: none; border: none; cursor: default; }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 8px var(--glow); }
.cal-day.studied { background: var(--bg-panel); }
.cal-num { font-size: 11px; color: var(--text-dim); line-height: 1; }
.cal-day.studied .cal-num { color: var(--text); }
.cal-stamp { color: var(--accent); line-height: 1; }
.cal-ups { margin: 6px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.8; color: var(--text-dim); }
.icon-btn {
  background: var(--bg-panel-2); color: var(--text); cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}

/* EX tab + prestige */
.seg-btn.ex-tab { color: var(--accent); }
.seg-btn.ex-tab.on { background: var(--accent); color: #2f3327; }
.prestige-row { border: 1px dashed var(--accent); border-radius: 10px; padding: 10px; margin-top: 10px; }

/* fixed 自由工場 row (subjects list) */
.subj-item.fixed { border-color: var(--accent); }
