/* ============================================================
   毎日ナンプレ — style.css
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  color-scheme: light;
  --bg:      #f8fafc;
  --bg2:     #f1f4f8;
  --bg3:     #e3e8ef;
  --surface: #ffffff;
  --control-surface: #eef4fa;
  --text:    #111827;
  --text2:   #4b5563;
  --text3:   #6b7280;
  --border:  #8f98a3;
  --border2: #c7ccd4;
  --accent:  #004b9b;
  --acc-bg:  #e8f3ff;
  --acc-bg2: #f5faff;
  --rel-bg:  #e9ecef;
  --same-bg: #fff1a6;
  --same-text: #3d2f00;
  --same-ring: #7a5c00;
  --err-bg:  #ffe3e8;
  --error:   #b00020;
  --warn:    #b45309;
  --ok:      #16703a;
  --menu-w:  220px;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { font-family: inherit; }

html { background: var(--bg); }

/* ── Base ──────────────────────────────────────────────────── */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── App Layout ─────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;        /* dynamic viewport height (mobile safe) */
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

#mc {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

#mc.no-scroll { overflow-y: auto; }

/* ── Bottom Tab Bar ─────────────────────────────────────────── */
#btabs {
  flex-shrink: 0;
  display: flex;
  border-top: 0.5px solid var(--border);
  background: var(--surface);
  padding-bottom: 0;
  min-height: 68px;
}

.tbb {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 0 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--text3);
  touch-action: manipulation;
  transition: color 0.15s;
}

.tbb .ti { font-size: 26px; }
.tbb.on  { color: var(--accent); }
#app.game-mode #btabs { display: none; }

/* ── Shared Buttons ─────────────────────────────────────────── */
.sdkd {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 16px;
  border: 0.5px solid var(--border);
  cursor: pointer;
  background: transparent;
  color: var(--text2);
  touch-action: manipulation;
  transition: all 0.12s;
}
.sdkd.on {
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
  border-color: var(--text);
}

/* ── Problem List Item ──────────────────────────────────────── */
.pitm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  margin-bottom: 10px;
  background: var(--bg2);
  border-radius: 12px;
  border: 0.5px solid var(--border2);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.1s;
}
.pitm:active { opacity: 0.7; }
.level-panel {
  margin: 0 0 14px;
  padding: 14px;
  border-radius: 8px;
  background: var(--bg2);
  border: 0.5px solid var(--border2);
}
.level-panel-head,
.home-list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.level-panel-head small {
  display: block;
  color: var(--text2);
  font-size: 15px;
  margin-bottom: 2px;
}
.level-panel-head strong {
  display: block;
  color: var(--text);
  font-size: 26px;
  line-height: 1.1;
}
.level-count,
.level-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
}
.level-count { padding: 5px 9px; }
.level-badge {
  min-width: 48px;
  padding: 5px 8px;
}
.level-meter {
  height: 7px;
  margin: 10px 0 8px;
  border-radius: 999px;
  background: var(--bg3);
  overflow: hidden;
}
.level-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.level-panel p {
  color: var(--text2);
  font-size: 15px;
  line-height: 1.55;
}
.level-divider {
  margin: 18px 2px 8px;
  color: var(--text2);
  font-size: 15px;
  font-weight: 700;
}

.level-window {
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 14px;
  touch-action: pan-y;
}
.level-window-head {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.level-nav {
  aspect-ratio: 1;
  border: 1px solid var(--border2);
  border-radius: 999px;
  background: var(--control-surface);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}
.level-nav:disabled {
  color: var(--text3);
  opacity: 0.35;
  cursor: default;
}
.level-window-title {
  text-align: center;
  min-width: 0;
}
.level-window-title strong {
  display: block;
  color: var(--text);
  font-size: 22px;
  line-height: 1.2;
}
.level-window-title small {
  display: block;
  color: var(--text2);
  font-size: 15px;
  margin-top: 2px;
}
.level-window-meter {
  height: 6px;
  margin: 0 4px 10px;
  border-radius: 999px;
  background: var(--bg3);
  overflow: hidden;
}
.level-window-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
}
.level-problems {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.level-window .pitm {
  margin-bottom: 0;
}
.pitm-loading {
  cursor: default;
  opacity: 0.76;
}

/* ── Sudoku Board ───────────────────────────────────────────── */
.sdk-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  border: 2.5px solid var(--text);
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.sdk-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-right: 0.5px solid var(--border2);
  border-bottom: 0.5px solid var(--border2);
  box-sizing: border-box;
  transition: background 0.07s, box-shadow 0.07s;
  position: relative;
  font-size: clamp(20px, 5.8vw, 28px);
}

/* Box separator lines */
.sdk-cell.rb { border-right: 2.5px solid var(--text); }
.sdk-cell.bb { border-bottom: 2.5px solid var(--text); }

/* Cell states */
.sdk-cell.sel  {
  background: var(--surface) !important;
  box-shadow: inset 0 0 0 4px var(--accent);
  z-index: 1;
}
.sdk-cell.rel  { background: var(--rel-bg); }
.sdk-cell.same {
  background: var(--same-bg);
  color: var(--same-text);
  font-weight: 700;
  box-shadow: inset 0 0 0 3px var(--same-ring);
}
/* Number colors */
.sdk-cell.given { font-weight: 700; color: var(--text); }
.sdk-cell.user  { color: var(--accent); font-weight: 700; }
.sdk-cell.same.given,
.sdk-cell.same.user { color: var(--same-text); }
.sdk-cell.err {
  background: var(--err-bg) !important;
  box-shadow: inset 0 0 0 3px var(--error);
  color: var(--error) !important;
}

/* Memo grid inside a cell */
.sdkmn {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
  box-sizing: border-box;
}
.sdkmn span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(10px, 3.2vw, 14px);
  color: var(--accent);
  font-weight: 600;
  line-height: 1;
}

/* ── Game Controls ──────────────────────────────────────────── */
.sdk-ctrl {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 11px 6px;
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: 8px;
  min-height: 56px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text2);
  touch-action: manipulation;
  transition: all 0.1s;
}
.sdk-ctrl .ti { font-size: 20px !important; }
.sdk-ctrl.on {
  background: var(--acc-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Number Pad ─────────────────────────────────────────────── */
.sdk-npad {
  aspect-ratio: 1;
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: 8px;
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  touch-action: manipulation;
  transition: transform 0.08s;
}
.sdk-npad:active { transform: scale(0.87); }
.sdk-npad.complete,
.sdk-npad:disabled {
  background: var(--bg3);
  border-color: var(--border);
  color: var(--text3);
  cursor: default;
  opacity: 0.62;
  pointer-events: none;
  transform: none;
}
/* ── Hamburger Menu ─────────────────────────────────────────── */
#hmenu {
  display: none;
  position: absolute;
  top: 45px;
  left: 0;
  width: var(--menu-w);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 0 0 14px 0;
  z-index: 30;
}

.hmenu-section {
  padding: 12px 14px;
  border-bottom: 0.5px solid var(--border2);
}
.hmenu-section:last-child { border-bottom: none; }

.hmenu-label {
  font-size: 15px;
  color: var(--text3);
  margin-bottom: 8px;
}

.btn-hint {
  width: 100%;
  padding: 11px;
  background: rgba(245,158,11,0.12);
  border: 0.5px solid rgba(245,158,11,0.4);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  color: #92400e;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
}
.btn-reset {
  width: 100%;
  padding: 11px;
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
}

/* ── Overlay / Modal ────────────────────────────────────────── */
.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.46);
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-card {
  background: var(--bg);
  border-radius: 16px;
  padding: 24px 18px;
  text-align: center;
  width: min(340px, 92%);
  border: 0.5px solid var(--border);
}

/* ── Hint Modal ─────────────────────────────────────────────── */
.hint-card {
  width: min(360px, 94%);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}
.hint-copy { color: var(--text2); font-size: 16px; line-height: 1.65; }
/* ── Calendar ───────────────────────────────────────────────── */
.cal-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
}
.cal-table th {
  padding: 4px 0;
  font-size: 15px;
  color: var(--text2);
  text-align: center;
  font-weight: 400;
}
.cal-day {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 16px;
  margin: 2px auto;
  cursor: pointer;
  color: var(--text2);
}
.cal-day.today  { border: 1.5px solid var(--accent); font-weight: 500; color: var(--accent); }
.cal-day.sel    { background: var(--text); color: var(--bg); font-weight: 500; }
.cal-day.future { color: var(--border); cursor: default; }

/* ── Screen Padding ─────────────────────────────────────────── */
.screen { padding: 12px; }

/* ── Accessibility ──────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}


/* ── Local icon fallback (external icon CDN removed for offline PWA) ── */
.ti {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  line-height: 1;
}
.ti-layout-list::before { content: "▦"; }
.ti-calendar::before    { content: "□"; }
.ti-chevron-right::before { content: "›"; }
.ti-menu-2::before      { content: "☰"; }
.ti-bulb::before        { content: "💡"; font-size: 0.9em; }
.ti-refresh::before     { content: "↻"; }
.ti-eraser::before      { content: "⌫"; }
.ti-pencil::before      { content: "✎"; }
.ti-backspace::before   { content: "⌫"; }


/* ── Home / List Screens ───────────────────────────────────── */
.home-screen { display: flex; flex-direction: column; gap: 18px; }
.hero-card {
  padding: 22px 18px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--acc-bg), var(--bg2));
  border: 0.5px solid var(--border2);
}
.hero-card .eyebrow { color: var(--accent); font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.hero-card h1 { font-size: 27px; line-height: 1.25; margin-bottom: 8px; }
.hero-card p { color: var(--text2); font-size: 16px; line-height: 1.65; }
.home-section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-head h2 { font-size: 18px; font-weight: 700; }
.home-list { display: flex; flex-direction: column; gap: 8px; }
.home-list-item,
.daily-card {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border: 0.5px solid var(--border2);
  border-radius: 14px;
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.home-list-item strong,
.daily-card strong { display: block; font-size: 18px; margin-bottom: 4px; }
.home-list-item small,
.daily-card small { display: block; color: var(--text2); font-size: 15px; line-height: 1.45; }
.home-list-arrow { color: var(--text3); font-size: 26px; line-height: 1; }
.done-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(22,163,74,0.12);
  color: var(--ok);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
.back-line {
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 16px;
  cursor: pointer;
  margin-bottom: 10px;
}
.screen-title { font-size: 22px; font-weight: 700; margin-bottom: 14px; }
.loading-text { padding: 40px 0; text-align: center; color: var(--text3); font-size: 16px; }
.problem-title { font-size: 17px; font-weight: 700; color: var(--text); }
.problem-status { font-size: 15px; color: var(--text3); margin-top: 4px; }
.problem-meta { display: flex; align-items: center; gap: 6px; color: var(--text3); }
.problem-icon { font-size: 18px; }
.pitm.status-done { border-color: rgba(22,163,74,0.35); background: rgba(22,163,74,0.08); }
.pitm.status-done .problem-status { color: var(--ok); font-weight: 600; }
.primary-action {
  width: 100%;
  padding: 14px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.daily-selected {
  border-top: 0.5px solid var(--border2);
  padding-top: 14px;
  margin-top: 14px;
}
.daily-selected-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.daily-status { margin-bottom: 10px; }
.home-footer-link { text-align: center; font-size: 15px; margin-top: 4px; }
.home-footer-link a { color: var(--text3); }

/* ── Game Responsive Layout ────────────────────────────────── */
.game-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 6px max(4px, env(safe-area-inset-bottom));
  background: var(--bg);
  overflow-y: auto;
  overflow-x: hidden;
}
.game-board {
  width: min(100%, 380px, calc(100dvh - 248px));
  max-width: calc(100vw - 12px);
  flex-shrink: 0;
  margin-bottom: 4px;
}
.game-status-row,
.game-controls,
.number-pad {
  width: min(100%, 380px, calc(100dvh - 248px));
  max-width: calc(100vw - 12px);
  flex-shrink: 0;
}
.game-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
}
.game-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  padding: 6px;
  background: var(--control-surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
}
.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px;
  background: var(--control-surface);
  border: 1px solid var(--border2);
  border-radius: 14px;
}
.btn-menu {
  width: 100%;
  padding: 11px;
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text2);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.clear-time {
  font-size: 16px;
  color: var(--text);
  background: var(--bg2);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 18px;
}
.howto-card { text-align: left; }
.howto-list { padding-left: 20px; margin-bottom: 16px; color: var(--text2); font-size: 15px; line-height: 1.75; }
.cal-day { position: relative; }
.cal-day.done:not(.sel) { background: rgba(22,163,74,0.10); color: var(--ok); }
.cal-dot { position: absolute; right: -1px; bottom: -1px; font-size: 12px; line-height: 1; }
.ti-check::before { content: "✓"; }
.ti-help::before { content: "?"; font-weight: 700; }

@media (max-height: 620px) {
  .sdk-ctrl { min-height: 50px; padding: 7px 4px; font-size: 15px; }
  .sdk-npad { border-radius: 7px; }
  .game-board,
  .game-status-row,
  .game-controls,
  .number-pad { width: min(100%, 352px, calc(100dvh - 230px)); }
}
@media (max-height: 540px) {
  .game-board,
  .game-status-row,
  .game-controls,
  .number-pad { width: min(100%, 300px, calc(100dvh - 228px), calc(100vw - 12px)); }
}

/* ── Loading States ────────────────────────────────────────── */
.screen-lead {
  color: var(--text2);
  font-size: 16px;
  line-height: 1.6;
  margin: -6px 0 14px;
}
.loading-panel,
.loading-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text2);
  font-size: 16px;
}
.loading-panel {
  min-height: 160px;
  flex-direction: column;
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: 14px;
}
.loading-inline {
  justify-content: flex-start;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: 12px;
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.loading-spinner.small {
  width: 16px;
  height: 16px;
  border-width: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
