:root{
  /* Use a JS-updated visible height to kill tiny mobile scroll */
  --app-h: 100dvh;

  --bg:#ffffff; --fg:#0b0b10; --muted:#8a9099; --border:#eceff3; --ok:#22c55e; --bad:#ef4444; --grid-line:rgba(24,66,105,.05);
  --iso-w:360; --iso-h:180;

  /* default (sans) stack for tiles */
  --tile-jp-font: "Noto Sans JP","Hiragino Kaku Gothic ProN","Yu Gothic","Noto Sans JP",Meiryo,Arial,sans-serif;
}
*{box-sizing:border-box}
html,body{
  height:100%;
  margin:0;
  background:#fff;
  color:var(--fg);
  font-family:system-ui,-apple-system,"Hiragino Kaku Gothic ProN","Yu Gothic","Noto Sans JP",Meiryo,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  overscroll-behavior: none;
}
body.dragging{cursor:grabbing}

/* Serif mode uses Noto Serif JP family */
body.serif-on{
  --tile-jp-font: "Noto Serif JP","Hiragino Mincho ProN","Yu Mincho","Noto Serif JP",serif;
}

/* ISO layer uses visible height var to avoid mobile 100vh bugs */
.iso{
  position:fixed; inset:0; z-index:0; pointer-events:none;
  width:100vw; height:var(--app-h);
}
#isoTrail path{shape-rendering:crispEdges}

/* Controls */
.btn{border:1px solid var(--border);border-radius:999px;padding:6px 12px;background:#fff;color:#000;font-size:12px;cursor:pointer}
.seg{display:inline-flex;border:1px solid var(--border);border-radius:999px;padding:3px;background:#fff}
.seg button{border:0;background:transparent;border-radius:999px;padding:5px 10px;font-size:12px;cursor:pointer;white-space:nowrap}
.seg button[aria-pressed="true"]{background:#0b0b10;color:#fff}
.tag{display:inline-flex;align-items:center;border:1px solid var(--border);border-radius:999px;padding:2px 8px;font-size:11px;color:#5f6671;background:#fff}
.tag input{margin-right:6px}
.klabel{border:1px solid var(--border);border-radius:999px;padding:6px 10px;background:#fff;color:#000;font-size:12px}
.hidden{display:none!important}

/* Mobile menu: hide globally; only show when .open is present */
.m-menu { display:none; position:fixed; inset:0; z-index:250; }
.m-menu.open { display:block; }

/* Modal (desktop + mobile) */
.modal{
  position:fixed; inset:0;
  display:flex; align-items:center; justify-content:center;
  padding:24px;
  background:rgba(0,0,0,.45);
  z-index:1000; /* above header/footer and mobile menu */
}
.modal .box{
  background:#fff;
  border:1px solid var(--border);
  border-radius:12px;
  padding:18px;
  max-width:520px;
  width:min(92vw,520px);
}
body.modal-open{ overflow:hidden; }

/* Header (desktop) */
.header{
  display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:10px;
  padding:8px 16px;border-bottom:1px solid var(--border);background:#fff;position:relative;z-index:2;
}
.left-wrap{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.logo{font-weight:800;color:#0b0b10;white-space:nowrap;font-size:18px;letter-spacing:.02em}
.right-controls{justify-self:end;display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.menu-btn{display:none}

/* Tips bar (desktop) */
.tipsbar{height:32px;background:#0b0b10;color:#fff;display:flex;align-items:center;justify-content:space-between;padding:0 30px 0 16px;position:relative;z-index:1;border-bottom:1px solid #000}
.tips{font-size:12px;opacity:.9}
.study-link{color:#fff;text-decoration:none;font-size:12px;opacity:.95}
.study-link:hover{text-decoration:underline}

/* Layout */
.quiz{
  height:var(--app-h);
  min-height:var(--app-h);
  display:grid;
  grid-template-rows:auto 32px 1fr auto;
  position:relative;z-index:1
}
.quiz-main{
  display:grid;place-items:center;padding:8px;
  min-height:0; /* allow the center to shrink and avoid page scroll */
  overflow:hidden; /* ensure no accidental overflow causes body scroll */
}
.arena{
  display:grid;
  grid-template-areas:"top top top" "left center right" "bottom bottom bottom";
  grid-template-columns:1fr minmax(220px,460px) 1fr;
  grid-template-rows:1fr auto 1fr;
  align-items:center;justify-items:center;
  width:min(1000px,94vw);height:min(74vh,600px)
}
.iso-anchor{grid-area:center;width:0;height:0;pointer-events:none}
.prompt{grid-area:center;text-align:center;font-size:clamp(20px,4vw,30px);font-weight:800;color:#0b0b10}

/* Tile cards */
.opt{
  position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;
  background:#fff;border-radius:16px;border:1px solid var(--border);
  transition:transform .06s,border-color .12s,box-shadow .12s, background .12s;
  width:100%;height:100%;max-width:480px;cursor:pointer;user-select:none;padding:10px
}
.opt:hover{border-color:#e2e6ee;box-shadow:0 6px 24px rgba(0,0,0,.08)}
.opt:active{transform:scale(.985)}
.opt.correct{outline:2px solid var(--ok)}
.opt.wrong{outline:2px solid var(--bad)}
.opt .jp{font-family:var(--tile-jp-font); font-weight:900;font-size:clamp(28px,6vw,56px);line-height:1;color:#000}
.opt .reading{margin-top:6px;font-size:clamp(12px,2.2vw,15px);color:#8a9099;opacity:.85}

/* Serif mode weight override (real Bold 700, no fake bold) */
body.serif-on .opt .jp{
  font-weight:700;
  font-synthesis-weight:none;
}

.arrow{position:absolute;width:18px;height:18px;color:#98a0aa;opacity:.65}
.top .arrow{bottom:6px;left:50%;transform:translateX(-50%) rotate(0deg)}
.right .arrow{left:6px;top:50%;transform:translateY(-50%) rotate(90deg)}
.bottom .arrow{top:6px;left:50%;transform:translateX(-50%) rotate(180deg)}
.left .arrow{right:6px;top:50%;transform:translateY(-50%) rotate(-90deg)}
.top{grid-area:top;height:22vh;min-height:110px;width:min(840px,92vw)}
.bottom{grid-area:bottom;height:22vh;min-height:110px;width:min(840px,92vw)}
.left{grid-area:left;height:22vh;min-height:110px;width:min(420px,42vw)}
.right{grid-area:right;height:22vh;min-height:110px;width:min(420px,42vw)}

/* Subtle glass mode (no shadows, same border as normal, a bit more transparent) */
body.glass-on .opt{
  background: linear-gradient(
    to bottom right,
    rgba(255,255,255,0.42),
    rgba(255,255,255,0.28)
  );
  backdrop-filter: saturate(140%) blur(6px);
  -webkit-backdrop-filter: saturate(140%) blur(6px);
  border: 1px solid var(--border);
  box-shadow: none;
}

/* Prevent hover shadow when glass is on */
body.glass-on .opt:hover{
  box-shadow: none;
  border-color: var(--border);
}

/* Footer */
.quiz-footer{
  display:grid;
  grid-template-columns:1fr auto auto auto auto;
  align-items:center;gap:10px;
  padding:10px 16px 14px;position:relative;z-index:1
}
.bar-track{width:100%;height:6px;background:rgba(0,0,0,.08);border-radius:999px;overflow:hidden}
.bar{height:6px;width:0%;background:#0b0b10;border-radius:999px;transition:width .25s ease}
.loop-pill{display:none}
.loop-pill.active{display:inline-flex}

/* -------- MOBILE -------- */
@media (max-width:680px){
  :root{ --iso-w:220; --iso-h:110; }

  /* lock the page, avoid tiny scroll */
  html, body { overflow:hidden; }

  /* Minimal header (keep menu at right) */
  .header{grid-template-columns:auto 1fr auto;gap:10px;padding:8px 12px}
  .header .right-controls{display:none}
  .header .seg{display:none}
  .header #kanaSets, .header #kanjiLevels{display:none}
  .logo{font-size:16px}
  .menu-btn{display:inline-flex;justify-self:end;align-items:center;justify-content:center;width:36px;height:32px;border:1px solid var(--border);border-radius:8px;background:#fff;cursor:pointer}
  .menu-btn .bars{display:block;width:18px;height:12px;position:relative}
  .menu-btn .bars::before,.menu-btn .bars::after,.menu-btn .bars span{content:"";position:absolute;left:0;right:0;height:2px;background:#0b0b10;border-radius:2px}
  .menu-btn .bars::before{top:0}.menu-btn .bars span{top:5px}.menu-btn .bars::after{bottom:0}

  /* Mobile menu sheet */
  .m-menu{display:none;position:fixed;inset:0;z-index:250}
  .m-menu.open{display:block}
  .m-backdrop{position:absolute;inset:0;background:rgba(0,0,0,.28)}
  .m-sheet{position:absolute;left:0;right:0;top:0;background:#fff;border-bottom:1px solid var(--border);box-shadow:0 10px 30px rgba(0,0,0,.18);border-radius:0 0 16px 16px;padding:10px 12px 14px}
  .m-sheet-head{display:flex;align-items:center;justify-content:space-between;padding-bottom:8px;border-bottom:1px solid var(--border)}
  .m-title{font-weight:700;font-size:14px}
  .menu-close{border:1px solid var(--border);background:#fff;border-radius:8px;padding:6px 10px;cursor:pointer}
  .m-menu-content{display:grid;gap:10px;padding-top:10px}
  .m-menu-content .seg{display:inline-flex;max-width:100%;overflow:auto}
  .m-menu-content .seg::-webkit-scrollbar{display:none}
  .m-menu-content .right-controls{display:flex !important;gap:10px;flex-wrap:wrap}

  body.menu-open{overflow:hidden}

  /* Black bar: study link left, hint hidden */
  .tipsbar{padding:0 12px;justify-content:flex-start}
  .tips{display:none}
  .study-link{font-size:13px;margin:0}

  /* Arena (mobile) — fully flexible, centered, never forces page scroll */
  .arena{
    --center-w: clamp(100px, 22vw, 140px);
    width:min(96vw,520px);
    height:100%;
    max-height:100%;
    margin:0 auto;
    grid-template-areas:"top top top" "left center right" "bottom bottom bottom";
    grid-template-columns:1fr var(--center-w) 1fr;
    grid-template-rows:minmax(84px,1fr) auto minmax(84px,1fr);
    gap:8px;align-items:center;justify-items:center;
  }
  .prompt{max-width:calc(var(--center-w) - 8px);font-size:clamp(12px,3.6vw,14px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin:0}
  .top,.bottom{justify-self:center;width:min(92vw,440px);min-height:clamp(84px,22vh,150px)}
  .left,.right{aspect-ratio:1/1;width:100%;min-height:0;max-width:300px}
  .opt{border-radius:12px;padding:8px}
  .opt .jp{font-size:clamp(24px,9vw,34px)}
  .opt .reading{font-size:clamp(10px,3vw,13px)}
  .arrow{width:16px;height:16px}

  /* Footer (with safe-area padding) */
  .quiz-footer{
    grid-template-columns:repeat(3,1fr);
    grid-template-areas:
      "bar bar bar"
      "loop loop loop"
      "shot ig stats";
    gap:8px;
    padding:8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .bar-track{grid-area:bar}
  #loopPill{grid-area:loop;justify-self:center}
  #shotBtn{grid-area:shot}
  #igShotBtn{grid-area:ig}
  #openStats{grid-area:stats}
}