* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: #f2f2f7;
  color: #1c1c1e;
  min-height: 100vh;
  padding: 16px;
  padding-top: 68px;
  padding-bottom: 32px;
}
.container { max-width: 540px; margin: 0 auto; }

/* Top bar (portrait: horizontal) */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  background: white;
  border-bottom: 1px solid #e5e5ea;
  z-index: 50;
}
.hamburger-btn {
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.85);
  border: 2px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.top-goal-label {
  font-size: 0.68em;
  font-weight: 600;
  color: #8e8e93;
  flex-shrink: 0;
}
/* Progress bar (portrait: horizontal) */
.progress-track { background: #e5e5ea; border-radius: 4px; overflow: hidden; }
.top-track {
  flex: 1;
  height: 6px;
  width: auto;
  position: relative;
}
.progress-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--pct, 0%);
  background: linear-gradient(90deg, #007aff, #34aadc);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.progress-fill.complete { background: linear-gradient(90deg, #34c759, #30d158); }
.top-goal-count {
  font-size: 0.78em;
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
  line-height: 1.3;
  white-space: nowrap;
}
.top-goal-count span { color: #8e8e93; font-weight: 400; }

/* Hamburger menu */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
}
.menu-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 260px;
  background: white;
  padding: 52px 0 24px;
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0,0,0,0.18);
}
.menu-app-info {
  padding: 4px 20px 16px;
  border-bottom: 1px solid #f2f2f7;
  margin-bottom: 6px;
}
.menu-app-title { font-size: 1.1em; font-weight: 700; margin-bottom: 4px; }
.menu-app-meta { font-size: 0.75em; color: #8e8e93; }
.menu-item {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 1px solid #f9f9f9;
  text-align: left;
  font-size: 0.95em;
  font-weight: 600;
  color: #1c1c1e;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.menu-item:active { background: #f2f2f7; }

/* Question card */
.question-card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75em;
  color: #8e8e93;
  margin-bottom: 10px;
}
.meta-sub { font-weight: 600; }
.meta-level { background: #f2f2f7; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.question-text { font-size: 0.9em; color: #8e8e93; text-align: center; margin-bottom: 4px; }
#score-display { display: flex; justify-content: center; min-height: 200px; align-items: center; flex-wrap: wrap; }
#score-display.scrollable { overflow-x: auto; -webkit-overflow-scrolling: touch; justify-content: flex-start; flex-wrap: nowrap; }
#score-display.scrollable > svg { flex-shrink: 0; }

/* Choices */
.choices-section {
  background: white;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice-btn {
  padding: 18px 8px;
  font-size: 1.15em;
  font-weight: 700;
  border: 2px solid #e5e5ea;
  background: #f9f9f9;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.12s;
  -webkit-tap-highlight-color: transparent;
  color: #1c1c1e;
}
.choice-btn:active:not(:disabled) { transform: scale(0.95); }
.choice-btn:hover:not(:disabled) { border-color: #007aff; background: #f0f7ff; }
.choice-btn:disabled { cursor: not-allowed; }
.choice-btn.correct { background: #34c759; border-color: #34c759; color: white; }
.choice-btn.wrong { background: #ff3b30; border-color: #ff3b30; color: white; }
.feedback { text-align: center; margin-top: 12px; min-height: 22px; font-size: 0.9em; font-weight: 600; }
.feedback.correct { color: #34c759; }
.feedback.wrong { color: #ff3b30; }
.next-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 22px 15px;
  font-size: 1em;
  font-weight: 700;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 12px;
  margin-top: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.next-btn:disabled { background: #c7c7cc; cursor: not-allowed; }
.next-btn:active:not(:disabled) { opacity: 0.85; }
.next-btn.orange { background: #ff9500; }
.next-btn.orange:disabled { background: #c7c7cc; }

/* Bottom bar */
.bottom-bar {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.stats-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 16px;
  background: white;
  border: 1.5px solid #e5e5ea;
  border-radius: 12px;
  font-size: 0.9em;
  font-weight: 600;
  color: #1c1c1e;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Calendar overlay */
.calendar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.calendar-modal {
  background: white;
  border-radius: 22px;
  padding: 24px 20px 20px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 1.1em;
}
.cal-nav-btn {
  background: none;
  border: none;
  font-size: 1.6em;
  cursor: pointer;
  color: #007aff;
  padding: 4px 10px;
  line-height: 1;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}
.cal-day-label { font-size: 0.8em; color: #8e8e93; font-weight: 600; padding: 4px 0 8px; }
.cal-day-label:first-child { color: #ff3b30; }
.cal-day-label:nth-child(7) { color: #007aff; }
.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  border-radius: 50%;
  color: #1c1c1e;
}
.cal-day.practiced { background: #007aff; color: white; font-weight: 700; }
.cal-day.today:not(.practiced) { border: 2px solid #007aff; color: #007aff; font-weight: 700; }
.cal-day.empty { pointer-events: none; }
.cal-summary {
  display: flex;
  justify-content: space-around;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f2f2f7;
}
.cal-summary .stats-summary-label { font-size: 0.9em; }
.cal-summary .stats-summary-value { font-size: 1.5em; }

/* Stats panel */
.stats-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.stats-panel {
  background: white;
  border-radius: 20px;
  padding: 18px 16px;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
}
.stats-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.stats-tab {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1.5px solid #e5e5ea;
  background: white;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  color: #1c1c1e;
  -webkit-tap-highlight-color: transparent;
}
.stats-tab.active { background: #007aff; border-color: #007aff; color: white; }
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88em;
  font-weight: 600;
}
.summary-accuracy { font-size: 1.1em; font-weight: 700; }
.summary-detail { font-size: 0.78em; color: #8e8e93; margin-top: 4px; }

/* Question grid */
.stats-question-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.q-card {
  border-radius: 10px;
  padding: 10px 6px 8px;
  text-align: center;
  border: 2px solid transparent;
}
.q-card .q-note { font-size: 1.05em; font-weight: 700; }
.q-card .q-accuracy { font-size: 0.72em; margin-top: 4px; font-weight: 600; }
.q-card.strong  { background: #e3f9e5; border-color: #34c759; color: #1a7a30; }
.q-card.medium  { background: #fff3e0; border-color: #ff9500; color: #9a5500; }
.q-card.weak    { background: #ffe5e5; border-color: #ff3b30; color: #b52020; }
.q-card.unseen  { background: #f2f2f7; border-color: #e5e5ea; color: #8e8e93; }
.q-card.locked  { background: #f9f9f9; border-color: #f2f2f7; color: #c7c7cc; }
.stats-divider { height: 1px; background: #f2f2f7; margin: 14px 0; }
.stats-summary { display: flex; justify-content: space-around; }
.stats-summary-item { text-align: center; }
.stats-summary-label { color: #8e8e93; font-size: 0.82em; }
.stats-summary-value { font-weight: 700; font-size: 1.2em; margin-top: 2px; }
.reset-btn {
  display: block;
  margin: 12px auto 0;
  background: none;
  border: none;
  color: #ff3b30;
  font-size: 0.82em;
  cursor: pointer;
  padding: 4px 8px;
}

/* Stats subcategory cards */
.subcat-cards {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.subcat-card {
  background: #f2f2f7;
  border-radius: 12px;
  padding: 12px 10px;
  cursor: pointer;
  border: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  min-width: 110px;
}
.subcat-card.active { background: #e8f2ff; border-color: #007aff; }
.sc-name { font-weight: 700; font-size: 0.85em; margin-bottom: 6px; color: #1c1c1e; }
.sc-acc { font-size: 1.05em; font-weight: 700; margin-bottom: 3px; }
.sc-meta { font-size: 0.72em; color: #8e8e93; }
.q-table { width: 100%; border-collapse: collapse; font-size: 0.82em; }
.q-table th { color: #8e8e93; font-weight: 600; padding: 4px 6px 6px; text-align: right; font-size: 0.9em; }
.q-table th:first-child { text-align: left; }
.q-table td { padding: 10px 6px; border-bottom: 1px solid #f2f2f7; vertical-align: middle; }
.q-table tr:last-child td { border-bottom: none; }
.q-table .col-label { font-weight: 600; }
.q-table .col-acc, .q-table .col-time, .q-table .col-due { text-align: right; }
.q-table .col-time, .q-table .col-due { color: #8e8e93; }
.acc-strong { color: #34c759; }
.acc-medium { color: #ff9500; }
.acc-weak   { color: #ff3b30; }
.acc-unseen { color: #8e8e93; }
.acc-locked { color: #c7c7cc; }

/* Unlock progress */
.sc-unlock { font-size: 0.7em; color: #007aff; font-weight: 600; margin-top: 5px; }
.sc-unlock.done { color: #34c759; }

.unlock-section {
  background: #f0f4ff;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  font-size: 0.82em;
}
.unlock-section.done { background: #e3f9e5; color: #1a7a30; font-weight: 600; padding: 10px 12px; }
.up-header { font-weight: 700; color: #1c1c1e; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.up-count { color: #007aff; font-weight: 700; }
.up-bar { height: 5px; background: #c7d2fe; border-radius: 3px; margin-bottom: 8px; overflow: hidden; }
.up-fill { height: 100%; background: #007aff; border-radius: 3px; transition: width 0.3s; }
.up-cond { font-size: 0.85em; color: #8e8e93; margin-bottom: 10px; }
.up-items { display: flex; flex-wrap: wrap; gap: 6px; }
.up-item {
  background: white;
  border: 1.5px solid #c7d2fe;
  border-radius: 8px;
  padding: 6px 8px;
  text-align: center;
  min-width: 54px;
}
.up-item.done { background: #e3f9e5; border-color: #34c759; }
.up-note-name { font-weight: 700; font-size: 0.95em; color: #1c1c1e; }
.up-note-stat { font-size: 0.82em; color: #8e8e93; margin-top: 2px; }
.up-item.done .up-note-name { color: #1a7a30; }
.up-item.done .up-note-stat { color: #34c759; }

/* Stats table row interactions */
.q-row { cursor: pointer; }
.q-row:active td { background: #f2f2f7; }
.col-lv { font-size: 0.72em; color: #8e8e93; font-weight: 400; margin-left: 5px; }

/* Accuracy graph */
.stats-graph-wrap {
  margin-bottom: 14px;
}
.stats-graph-title {
  font-size: 0.78em;
  color: #8e8e93;
  font-weight: 600;
  margin-bottom: 6px;
}
.stats-graph-svg {
  display: block;
  width: 100%;
  height: auto;
}
.stats-graph-current {
  font-size: 0.82em;
  color: #8e8e93;
  margin-top: 4px;
  text-align: right;
}
.stats-graph-current strong { color: #007aff; }

/* Answer overlay */
.answer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.answer-modal {
  background: white;
  border-radius: 20px;
  padding: 24px 20px 20px;
  width: 100%;
  max-width: 400px;
}
.answer-meta {
  font-size: 0.78em;
  color: #8e8e93;
  font-weight: 600;
  margin-bottom: 12px;
}
.answer-question {
  font-size: 1em;
  font-weight: 700;
  margin-bottom: 14px;
  line-height: 1.5;
}
.answer-answer {
  font-size: 1.05em;
  font-weight: 700;
  color: #007aff;
  margin-bottom: 10px;
}
.answer-hint {
  font-size: 0.85em;
  color: #8e8e93;
  background: #f2f2f7;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.answer-stats {
  display: flex;
  gap: 14px;
  font-size: 0.82em;
  color: #8e8e93;
  margin-bottom: 18px;
}
.answer-close-btn {
  display: block;
  width: 100%;
  padding: 14px;
  background: #f2f2f7;
  border: none;
  border-radius: 12px;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  color: #1c1c1e;
}
.answer-close-btn:active { background: #e5e5ea; }

/* Completion */
.completion-card {
  background: white;
  border-radius: 16px;
  padding: 40px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  text-align: center;
  margin-bottom: 12px;
}
.completion-emoji { font-size: 2.5em; margin-bottom: 14px; }
.completion-title { font-size: 1.3em; font-weight: 700; margin-bottom: 10px; }
.completion-stats { font-size: 0.9em; color: #8e8e93; margin-bottom: 6px; }
.completion-next { font-size: 0.82em; color: #c7c7cc; margin-bottom: 28px; }
.daily-done { opacity: 0.45; cursor: not-allowed !important; }

/* Focus practice card */
.focus-card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.focus-header {
  font-size: 0.78em;
  font-weight: 600;
  color: #8e8e93;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.focus-cat-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.focus-cat-tab {
  padding: 5px 14px;
  border-radius: 18px;
  border: 1.5px solid #e5e5ea;
  background: white;
  font-size: 0.82em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  color: #1c1c1e;
  -webkit-tap-highlight-color: transparent;
}
.focus-cat-tab.active { background: #5856d6; border-color: #5856d6; color: white; }
.focus-subcat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}
.focus-subcat-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  border: 2px solid #e5e5ea;
  background: #f9f9f9;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.1s, background 0.1s;
}
.focus-subcat-btn.active { border-color: #5856d6; background: #f0efff; }
.focus-subcat-btn .fsb-name { font-size: 0.82em; font-weight: 600; color: #1c1c1e; text-align: center; }
.focus-subcat-btn .fsb-count { font-size: 0.72em; color: #8e8e93; margin-top: 2px; }
.focus-subcat-btn.active .fsb-name { color: #5856d6; }

/* Landscape layout */
@media (min-aspect-ratio: 1/1) and (min-width: 500px) {
  html, body { height: 100%; }
  body { padding: 6px; padding-top: 6px; padding-bottom: 6px; box-sizing: border-box; }
  .container { max-width: calc(100vw - 86px); margin-left: 86px; margin-right: 0; height: 100%; }
  #main-layout { height: 100%; }

  /* Landscape: vertical left sidebar */
  .top-bar {
    top: 0; left: 0; bottom: 0; right: auto;
    width: 80px; height: auto;
    flex-direction: column;
    padding: 14px 6px;
    border-bottom: none;
    border-right: 1px solid #e5e5ea;
  }
  .hamburger-btn {
    width: 68px; height: 68px;
    min-width: 68px; min-height: 68px;
    font-size: 28px;
    border-radius: 14px;
  }
  .top-goal-label { text-align: center; }
  .top-track {
    flex: 1;
    width: 6px; height: auto;
    min-height: 60px;
  }
  .progress-fill {
    left: 0; right: 0; bottom: 0; top: auto;
    height: var(--pct, 0%);
    width: auto;
    background: linear-gradient(0deg, #007aff, #34aadc);
    transition: height 0.4s ease;
  }
  .progress-fill.complete { background: linear-gradient(0deg, #34c759, #30d158); }
  .top-goal-count span { display: block; }

  #main-layout {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 8px;
    align-items: stretch;
    margin-bottom: 0;
  }

  .question-card {
    padding: 8px 12px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: hidden;
  }
  .card-meta { margin-bottom: 4px; }
  .question-text { margin-bottom: 2px; font-size: 0.82em; }
  #score-display {
    min-height: 0;
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #score-display > svg {
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    display: block;
  }
  #score-display.scrollable {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
  }
  #score-display.scrollable > svg {
    max-width: none !important;
    flex-shrink: 0;
  }

  #answer-area {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
  }

  .choices-section {
    padding: 10px 12px;
    margin-bottom: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  /* Choices: single column, 4 rows */
  .choices { grid-template-columns: 1fr; gap: 5px; }
  .choice-btn { padding: 9px 8px; font-size: 0.9em; }

  .next-btn { padding: 9px; margin-top: 6px; font-size: 0.88em; }
  .feedback { margin-top: 6px; font-size: 0.82em; min-height: 18px; }

  .completion-card { padding: 16px; margin-bottom: 6px; }
  .completion-emoji { font-size: 1.8em; margin-bottom: 8px; }
  .completion-title { font-size: 1.1em; margin-bottom: 6px; }
  .completion-next { margin-bottom: 12px; }

  .focus-card { padding: 10px 12px; margin-bottom: 6px; }
}
