/* Hallmark · macrostructure: Workbench reward ledger · tone: quiet private-room luxury
 * Hallmark · pre-emit critique: P5 H5 E5 S5 R5 V5
 * contrast: pass · motion: LEVEL UP one-shot only · responsive: 320/390/667/1280/1920
 */

:root {
  --progression-surface: var(--v16-panel-strong);
  --progression-surface-soft: var(--v16-panel-soft);
  --progression-rule: var(--learn-rule);
  --progression-rule-strong: var(--learn-rule-strong);
  --progression-gold: var(--v16-gold);
  --progression-ivory: var(--v16-text);
  --progression-muted: var(--v16-muted);
  --progression-complete: var(--learn-good);
  --progression-focus: var(--learn-focus);
  --progression-lock: var(--learn-dim);
  --progression-shadow: var(--v16-shadow);
  --progression-ease-out: var(--learn-ease-out);
}

/* ---------- title: a restrained brass instrument, not a generic pill ---------- */
#screen-title #title-progression {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(72px, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: min(100%, 468px);
  max-width: none;
  min-height: 42px;
  margin: 8px auto 4px;
  padding: 8px 12px;
  overflow: hidden;
  border: 1px solid var(--title-line);
  border-radius: 7px;
  color: var(--title-copy);
  background: linear-gradient(180deg, var(--title-ink-glass), var(--title-ink-deep));
  box-shadow: inset 0 1px var(--v16-glint), 0 8px 22px var(--title-shadow);
}

#screen-title #title-progression::before {
  content: "";
  position: absolute;
  inset: -1px auto auto 12px;
  width: 64px;
  height: 1px;
  background: var(--title-gold);
  opacity: .82;
}

#screen-title #title-level {
  min-width: 46px;
  color: var(--title-gold-hi);
  font: 700 16px/1.1 var(--title-font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  white-space: nowrap;
}

#screen-title #title-progression .level-bar {
  position: relative;
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--title-line-dim);
  border-radius: 2px;
  background: var(--title-ink);
  box-shadow: inset 0 1px 3px var(--title-shadow);
}

#screen-title #title-progression .level-bar::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-top: 1px solid var(--v16-glint);
  pointer-events: none;
}

#screen-title #title-level-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--title-gold-low), var(--title-gold), var(--title-gold-hi));
  box-shadow: inset 0 1px var(--v16-glint);
  transition: none;
}

#screen-title #title-exp {
  color: var(--title-muted);
  font: 700 12px/1.2 var(--title-font-body);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#screen-title #title-progression[data-janou='true'] {
  border-color: var(--progression-focus);
}

#screen-title #title-progression[data-janou='true']::before,
#screen-title #title-progression[data-janou='true'] #title-level-fill {
  background: var(--title-ivory);
}

#screen-title #title-progression[data-janou='true'] #title-level {
  color: var(--title-ivory);
  letter-spacing: .12em;
}

/* ---------- result: one reward ledger; the fixed progress footer stays untouched ---------- */
#overlay-content .exp-summary {
  position: relative;
  max-width: 600px;
  margin: 12px auto 4px;
  padding: 0;
  overflow: hidden;
  border-block: 1px solid var(--progression-rule-strong);
  border-radius: 0;
  color: var(--progression-ivory);
  background: linear-gradient(90deg, transparent, var(--progression-surface-soft), transparent);
  box-shadow: none;
  text-align: left;
}

#overlay-content .exp-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 10px 20px;
  color: var(--progression-muted);
  font: 700 16px/1.3 var(--v16-font-body);
  letter-spacing: .04em;
}

#overlay-content .exp-total strong {
  color: var(--progression-gold);
  font: 700 clamp(30px, 4vw, 40px)/1 var(--v16-font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

#overlay-content .exp-breakdown {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--progression-rule);
  color: var(--progression-muted);
  font-size: 14px;
  line-height: 1.45;
}

#overlay-content .exp-breakdown-item {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}

#overlay-content .exp-breakdown-item strong {
  color: var(--progression-ivory);
  font-variant-numeric: tabular-nums;
}

#overlay-content .exp-breakdown-separator { color: var(--progression-rule-strong); }

#overlay-content .exp-achievement,
#overlay-content .exp-unlock {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 20px;
  border-top: 1px solid var(--progression-rule);
  color: var(--progression-ivory);
  font-size: 14px;
  line-height: 1.45;
}

#overlay-content .exp-achievement > span:last-child {
  color: var(--progression-gold);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#overlay-content .exp-achievement > span { margin-left: 0; }
#overlay-content .exp-achievement-label { color: var(--progression-ivory); }

#overlay-content .reward-mark {
  position: relative;
  width: 17px;
  height: 17px;
  border: 1px solid currentColor;
  color: var(--progression-gold);
}

#overlay-content .reward-mark-medal {
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px var(--progression-surface);
}

#overlay-content .reward-mark-medal::after {
  content: "";
  position: absolute;
  left: 4px;
  bottom: -6px;
  width: 7px;
  height: 7px;
  border-inline: 3px solid currentColor;
  transform: skewY(-15deg);
}

#overlay-content .reward-mark-unlock {
  width: 15px;
  height: 12px;
  margin-top: 4px;
  border-radius: 2px;
  color: var(--progression-complete);
}

#overlay-content .reward-mark-unlock::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -8px;
  width: 8px;
  height: 9px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
}

#overlay-content .exp-levelup {
  position: relative;
  margin: 0;
  padding: 14px 20px 12px;
  border-top: 1px solid var(--progression-rule-strong);
  color: var(--progression-gold);
  font: 700 clamp(20px, 3vw, 27px)/1.25 var(--v16-font-display);
  letter-spacing: .06em;
  text-align: center;
  text-shadow: 0 0 16px var(--progression-rule-strong);
  animation: progression-level-up 620ms var(--progression-ease-out) both;
}

#overlay-content .exp-levelup::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 8px;
  height: 1px;
  background: var(--progression-gold);
  box-shadow: 0 0 12px var(--progression-gold);
  opacity: .7;
}

#overlay-content .exp-unlock {
  grid-template-columns: 22px minmax(0, 1fr);
  color: var(--progression-complete);
}

#overlay-content .exp-now {
  margin: 0;
  padding: 8px 20px;
  border-top: 1px solid var(--progression-rule);
  color: var(--progression-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

@keyframes progression-level-up {
  from { opacity: 0; transform: translateY(7px) scale(.985); }
  58% { opacity: 1; transform: translateY(0) scale(1.012); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- achievements: a ruled ledger, not a wall of cards ---------- */
#achievements-dialog {
  inset: 0;
  width: min(820px, calc(100vw - 24px));
  max-width: 820px;
  height: min(780px, calc(100dvh - 24px));
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--progression-rule-strong);
  border-radius: 16px;
  color: var(--progression-ivory);
  background: linear-gradient(145deg, var(--progression-surface), var(--progression-surface-soft));
  box-shadow: 0 24px 80px var(--progression-shadow), inset 0 1px var(--v16-glint);
}

#achievements-dialog::backdrop {
  background: var(--learn-scrim);
  backdrop-filter: blur(8px);
}

#achievements-dialog .stats-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  max-height: none;
}

#achievements-dialog .stats-header {
  min-height: 76px;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--progression-rule);
  background: linear-gradient(180deg, var(--progression-surface-soft), transparent);
}

#achievements-dialog .stats-header small {
  color: var(--progression-muted);
  font: 800 11px/1.2 var(--v16-font-body);
  letter-spacing: .18em;
}

#achievements-dialog .stats-header h2 {
  margin: 4px 0 0;
  color: var(--progression-ivory);
  font: 700 23px/1.2 var(--v16-font-display);
  letter-spacing: .06em;
}

#achievements-dialog .stats-body {
  min-height: 0;
  padding: 0 24px 16px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--progression-rule-strong) var(--progression-surface);
  scrollbar-width: thin;
}

#achievements-dialog .stats-footer {
  min-height: 72px;
  padding: 12px 24px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--progression-rule);
  background: var(--progression-surface);
  box-shadow: 0 -12px 26px var(--progression-shadow);
}

#achievements-dialog .stats-footer .btn.primary {
  min-width: min(100%, 220px);
  min-height: 48px;
  margin-left: auto;
  font-size: 16px;
  white-space: nowrap;
}

#achievements-dialog .achv-progress-line {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 54px;
  margin: 0 -24px 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--progression-rule-strong);
  color: var(--progression-muted);
  background: var(--progression-surface);
  box-shadow: 0 8px 16px var(--progression-shadow);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#achievements-dialog .achv-summary-count {
  color: var(--progression-ivory);
  font-size: 14px;
}

#achievements-dialog .achv-summary-count strong {
  color: var(--progression-gold);
  font: 700 21px/1 var(--v16-font-display);
}

#achievements-dialog .achv-summary-level { text-align: right; }

#achievements-dialog .stats-section {
  margin: 0 0 24px;
}

#achievements-dialog .stats-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 0 8px;
  border: 0;
  color: var(--progression-gold);
  font: 700 16px/1.35 var(--v16-font-display);
  letter-spacing: .06em;
}

#achievements-dialog .stats-section h3::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--progression-rule);
}

#achievements-dialog .achv-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 24px;
  border-top: 1px solid var(--progression-rule);
}

#achievements-dialog .achv-row {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 0;
  border-bottom: 1px solid var(--progression-rule);
  border-radius: 0;
  color: var(--progression-ivory);
  background: transparent;
  font-size: 14px;
  line-height: 1.35;
}

#achievements-dialog .achv-status {
  position: relative;
  width: 10px;
  height: 10px;
  border: 1px solid var(--progression-rule-strong);
  transform: rotate(45deg);
}

#achievements-dialog .achv-row.achieved .achv-status {
  border-color: var(--progression-complete);
  background: var(--progression-complete);
}

#achievements-dialog .achv-row.achieved .achv-status::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 0;
  width: 3px;
  height: 6px;
  border: solid var(--progression-surface);
  border-width: 0 2px 2px 0;
}

#achievements-dialog .achv-label { min-width: 0; }

#achievements-dialog .achv-count {
  color: var(--progression-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#achievements-dialog .achv-exp {
  color: var(--progression-gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#achievements-dialog .achv-row.achieved { opacity: 1; }
#achievements-dialog .achv-row.achieved .achv-label { color: var(--progression-muted); }
#achievements-dialog .achv-row.achieved .achv-count { color: var(--progression-lock); }
#achievements-dialog .achv-row.achieved .achv-exp { color: var(--progression-complete); }

/* ---------- locks: readable waiting states, never a dimmed OFF switch ---------- */
#screen-title .learning-mode-option:has(#coach-mode-toggle:disabled),
.coach-style-row.locked,
.rule-item:has(.toggle.locked) {
  border-color: var(--progression-rule);
  color: var(--progression-muted);
}

#screen-title .learning-mode-option:has(#coach-mode-toggle:disabled) {
  background: linear-gradient(90deg, var(--progression-surface-soft), transparent);
}

#screen-title #coach-mode-lock-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--progression-gold);
  font-size: 12px;
  opacity: .82;
}

#screen-title #coach-mode-lock-note::before,
.rule-item .toggle.locked::before,
.coach-style-row.locked::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 1px;
  box-shadow: 0 -4px 0 -2px currentColor;
}

.coach-style-row.locked,
.rule-item .toggle.locked {
  opacity: .72;
  cursor: not-allowed;
}

.rule-item .toggle.locked {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--progression-muted);
  border-color: var(--progression-rule);
  background: var(--progression-surface-soft);
}

.rule-item select option:disabled { color: var(--progression-lock); }

/* Rules are a three-row shell: only the list scrolls; save/back is always reachable. */
#screen-rules .rules-box {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(680px, calc(100vw - 20px));
  height: min(720px, calc(100dvh - 20px));
  max-width: 680px;
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--progression-rule-strong);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--progression-surface), var(--progression-surface-soft));
  box-shadow: 0 20px 70px var(--progression-shadow), inset 0 1px var(--v16-glint);
}

#screen-rules .rules-box h2 {
  min-height: 62px;
  margin: 0;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--progression-rule);
  font: 700 22px/1.35 var(--v16-font-display);
}

#screen-rules #rules-list {
  min-height: 0;
  padding: 12px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--progression-rule-strong) var(--progression-surface);
  scrollbar-width: thin;
}

#screen-rules #btn-rules-done {
  width: auto;
  min-width: min(260px, calc(100% - 40px));
  min-height: 50px;
  margin: 12px 20px max(12px, env(safe-area-inset-bottom));
  justify-self: end;
  font-size: 16px;
  white-space: nowrap;
  box-shadow: 0 -10px 22px var(--progression-shadow);
}

@media (max-width: 620px) {
  #achievements-dialog {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
    border-radius: 12px;
  }

  #achievements-dialog .stats-header { min-height: 66px; padding: 12px 16px 8px; }
  #achievements-dialog .stats-header h2 { font-size: 20px; }
  #achievements-dialog .stats-body { padding-inline: 16px; }
  #achievements-dialog .stats-footer { min-height: 66px; padding-inline: 16px; }
  #achievements-dialog .achv-progress-line { margin-inline: -16px; padding-inline: 16px; }
  #achievements-dialog .achv-list { grid-template-columns: 1fr; }
  #achievements-dialog .achv-row { grid-template-columns: 16px minmax(0, 1fr) auto; }
  #achievements-dialog .achv-count { grid-column: 2; }
  #achievements-dialog .achv-exp { grid-column: 3; grid-row: 1 / span 2; }

  #overlay-content .exp-breakdown { gap-block: 8px; }
  #overlay-content .exp-breakdown-separator { display: none; }
}

@media (max-width: 380px) {
  #screen-title #title-progression { gap: 8px; padding-inline: 8px; }
  #achievements-dialog .achv-progress-line { align-items: flex-start; flex-direction: column; gap: 4px; }
  #achievements-dialog .achv-summary-level { text-align: left; }
}

@media (orientation: landscape) and (max-height: 430px) {
  #screen-rules .rules-box { height: calc(100dvh - 12px); }
  #screen-rules .rules-box h2 { min-height: 48px; padding-block: 8px; font-size: 19px; }
  #screen-rules #rules-list { padding-block: 8px; }
  #screen-rules #btn-rules-done { min-height: 46px; margin-block: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  #overlay-content .exp-levelup { animation: none; }
}
