/* The identity and theme selector are shared by both atlases. */
.topbar-inner {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  column-gap: clamp(14px, 2.2vw, 34px);
  min-height: 68px;
}
.topbar-inner .modes { justify-self: center; }
.brand { gap: 9px; }
.brand-mark {
  position: relative;
  width: 37px;
  height: 37px;
  overflow: hidden;
  border: 1px solid #63809e;
  border-radius: 11px;
  background: radial-gradient(circle at 64% 23%, #344b64, transparent 76%), #172235;
  box-shadow: inset 0 0 13px #15213540;
}
.brand-mark::before {
  content: "";
  position: absolute;
  width: 30px;
  height: 11px;
  border: 1px solid #cbe5eb8a;
  border-radius: 50%;
  transform: rotate(-35deg);
}
.brand-mark i, .brand-mark::after {
  display: block;
  background: #ffe1aa;
  clip-path: polygon(50% 0,60% 36%,100% 48%,63% 60%,50% 100%,39% 61%,0 50%,37% 37%);
}
.brand-mark i { position: relative; width: 22px; height: 25px; }
.brand-mark::after { content: ""; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; background: #c8faff; }
.brand-lockup { display: grid; gap: 3px; letter-spacing: 0; }
.brand-lockup strong { font: 750 18px/1.18 var(--sans); letter-spacing: .06em; }
.brand-lockup small { color: var(--soft); font: 500 10px/1.1 var(--sans); letter-spacing: .06em; }
.theme-switch {
  display: inline-flex;
  justify-self: end;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--paper);
}
.theme-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 31px;
  padding: 4px 10px;
  border-radius: 16px;
  background: transparent;
  color: var(--soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.25;
}
.theme-switch button[aria-pressed="true"] { color: var(--red-dark); background: var(--card); box-shadow: 0 1px 4px #382e1e24; }
.theme-switch button:focus-visible { outline-offset: 1px; }
.theme-space-icon, .theme-city-icon { position: relative; display: inline-block; width: 13px; height: 13px; flex: none; }
.theme-space-icon::before { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: currentColor; }
.theme-space-icon::after { content: ""; position: absolute; inset: 4px -1px; border: 1px solid currentColor; border-radius: 50%; transform: rotate(-28deg); }
.theme-city-icon {
  background: currentColor;
  clip-path: polygon(0 99%,0 45%,26% 45%,26% 26%,46% 26%,46% 4%,69% 4%,69% 52%,80% 52%,80% 32%,100% 32%,100% 99%);
}

:root[data-theme="space"] {
  color-scheme: dark;
  --paper: #080d1d;
  --card: #101a2c;
  --ink: #edf3fd;
  --soft: #afbdd3;
  --rule: #2b3951;
  --red: #8ce3db;
  --red-dark: #a5eddf;
  --red-pale: #1a343c;
  --olive: #a1e1bb;
  --edge: #41506d;
  --raised: #19253a;
  --ice: #8ce3db;
  --lilac: #bebafa;
  --sand: #f5c98a;
}
:root[data-theme="space"] body {
  background:
    radial-gradient(ellipse at 14% -15%, #1f2845 0, transparent 46rem),
    radial-gradient(ellipse at 99% 45%, #151a32 0, transparent 47rem),
    var(--paper);
}
:root[data-theme="space"] .topbar { background: #0d1424; border-color: #25324a; }
:root[data-theme="space"] .brand-mark { border-color: #51627b; box-shadow: inset 0 0 14px #65798a22, 0 0 14px #6ab1e511; }
:root[data-theme="space"] .brand-lockup small { color: #a0b1c9; }
:root[data-theme="space"] .theme-switch { background: #080e1c; border-color: #34415b; }
:root[data-theme="space"] .theme-switch button[aria-pressed="true"] { color: #e0e4ff; background: #303550; box-shadow: inset 0 0 0 1px #636c9566; }
:root[data-theme="space"] .mode { color: #abb8ce; }
:root[data-theme="space"] .mode:hover, :root[data-theme="space"] .mode[aria-pressed="true"] { color: #e3fcf6; }
:root[data-theme="space"] .mode[aria-pressed="true"]::after { height: 2px; background: var(--ice); box-shadow: 0 -2px 10px #9deae84d; }
:root[data-theme="space"] .completion { width: 119px; }
:root[data-theme="space"] #progress-text { color: #d0dfef; }
:root[data-theme="space"] progress { background: #2c384e; height: 4px; }
:root[data-theme="space"] progress::-webkit-progress-value { background: linear-gradient(90deg,#84bbf3,var(--ice)); }

:root[data-theme="space"] .map-counts { font-size: 13px; letter-spacing: .025em; margin: 0; }
:root[data-theme="space"] .count-number { color: #e4e9f8; font-family: ui-monospace,"SFMono-Regular",Consolas,monospace; }
:root[data-theme="space"] .atlas-filters { margin: 0 0 13px; gap: 6px 17px; }

:root[data-theme="space"] .panel, :root[data-theme="space"] .study-panel {
  border-color: #2c3a52;
  background: linear-gradient(125deg,#142035 0%,#10192b 63%);
  box-shadow: inset 0 1px #9db7d00c, 0 8px 24px #02071336;
}
:root[data-theme="space"] .panel { border-radius: 13px; }
:root[data-theme="space"] .map-panel .panel-heading { padding: 12px 17px; }
:root[data-theme="space"] .panel-heading h2 { font-size: 18px; }
:root[data-theme="space"] .map-breadcrumb { color: #9aadc6; }
:root[data-theme="space"] .map-breadcrumb > :not(:first-child)::before { color: #6d829d; }
:root[data-theme="space"] .map-panel .zoom-level {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 4px 9px; border: 1px solid #3a4b62; border-radius: 5px;
  color: #bdd9e4; background: #17273a; letter-spacing: .04em;
}
:root[data-theme="space"] .zoom-level::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--ice); box-shadow: 0 0 7px #99e9e896; }
:root[data-theme="space"] .map-surface { border-block-color: #34405a; background: #080d20; }
:root[data-theme="space"] .map-surface .compass { display: none; }
:root[data-theme="space"] .map-surface .map-legend {
  color: #c0cee2; background: #0c1426e6; border-color: #344561; border-radius: 5px;
  padding: 4px 8px; letter-spacing: .03em;
}
:root[data-theme="space"] .map-surface :is(.locate-word,.zoom-button) {
  color: #e0eefb; background: #121e32ed; border-color: #496078; box-shadow: 0 3px 12px #0106127a;
}
:root[data-theme="space"] .map-surface :is(.locate-word,.zoom-button):not(:disabled):hover { color: #cafff2; background: #26394d; }
:root[data-theme="space"] .map-surface .zoom-button:disabled { color: #8293a9; background: #172235; }
:root[data-theme="space"] .city-directory { background: #0b1526; border-color: #27374e; }
:root[data-theme="space"] .city-directory summary { color: #afcde0; }
:root[data-theme="space"] .directory-links button { color: #c0cee1; background: #18243a; border-color: var(--rule); }
:root[data-theme="space"] .directory-links button:hover { color: #d8fff5; border-color: #639594; }
:root[data-theme="space"] .route { padding: 16px 18px 19px; }
:root[data-theme="space"] #route-root { color: #e0eaf7; }
:root[data-theme="space"] .word-chip { background: #172337; color: #ccd8e8; border-color: #34425a; }
:root[data-theme="space"] .word-chip:hover { border-color: #7187a2; }
:root[data-theme="space"] .word-chip[aria-pressed="true"] { background: #20383f; border-color: #5b9a9a; color: #cafff1; }

.map-surface[data-map-theme="space"] .station[data-depth],
.map-surface[data-map-theme="space"][data-map-small] .station[data-depth],
.map-surface[data-map-theme="space"][data-narrow-street] .station[data-depth] {
  width: 98px; min-height: 34px; padding: 2px 3px;
  gap: 1px; display: flex; flex-direction: column; justify-content: center; align-items: center;
  border: 1px solid transparent; border-radius: 6px; isolation: auto;
  background: radial-gradient(ellipse at center,#080e20c9 22%,#0b122859 66%,transparent 80%);
  box-shadow: none; color: #ecf4ff; text-align: center;
  text-shadow: 0 1px 3px #040815, 0 0 6px #05091a;
}
.map-surface[data-map-theme="space"] .station[data-depth]::before,
.map-surface[data-map-theme="space"] .station .meaning-icon { display: none; }
.map-surface[data-map-theme="space"] .station[data-depth] .station-title {
  color: #f3f5ff; width: 100%; line-height: 1.2; font-size: 13px; font-weight: 690; letter-spacing: .015em;
}
.map-surface[data-map-theme="space"] .station[data-depth="2"] .station-title { font-size: 14px; }
.map-surface[data-map-theme="space"] .station[data-depth] .station-gloss { color: #c0ccdf; font-size: 10px; font-weight: 500; line-height: 1.2; }
.map-surface[data-map-theme="space"] .station[data-depth][aria-current],
.map-surface[data-map-theme="space"] .station[data-depth]:hover,
.map-surface[data-map-theme="space"][data-map-small] .station[data-depth]:is(:hover,[aria-current]),
.map-surface[data-map-theme="space"][data-narrow-street] .station[data-depth]:is(:hover,[aria-current]) {
  border-color: color-mix(in srgb,var(--station-ink) 52%,#273d57);
  background: #101b2fe8; box-shadow: 0 0 11px color-mix(in srgb,var(--station-ink) 17%,transparent);
}
.map-surface[data-map-theme="space"] .station[data-depth][aria-current] .station-title { color: #fff; }
.map-surface[data-map-theme="space"] .station[data-depth]:focus-visible { outline: 2px solid #bcf7eb; outline-offset: 2px; }
.map-surface[data-map-theme="space"] .station .station-check { top: -5px; right: -3px; background: #a2e7c8; color: #153432; }
.map-surface[data-map-theme="space"][data-map-small] .station[data-depth="0"] { width: 85px; }
.map-surface[data-map-theme="space"][data-narrow-street] .station[data-depth="2"] { width: 82px; }

:root[data-theme="space"] .detail-panel {
  border-top-color: #6a6279;
  background: radial-gradient(ellipse at top right, #30304888, transparent 16rem), var(--card);
}
:root[data-theme="space"] .detail-family { color: #cfdbec; color: color-mix(in srgb,var(--topic-color,#72aaa4) 37%,#eeefff); }
:root[data-theme="space"] .detail-family i { background: currentColor; box-shadow: 0 0 7px currentColor; }
:root[data-theme="space"] .word-heading { margin-top: 12px; }
:root[data-theme="space"] .word-title .root-part { color: #fad3a3; }
:root[data-theme="space"] .word-reading { color: #b8c6dd; }
:root[data-theme="space"] .word-meaning { color: #e7ebf8; }
:root[data-theme="space"] .pos-label { background: #1b2d3c; color: #b1d4df; }
:root[data-theme="space"] .level-badge { background: #3c2e25; color: #f2cf99; }
:root[data-theme="space"] .level-badge[data-level="N5"] { background: #213b33; color: #b6e5bd; }
:root[data-theme="space"] .level-badge[data-level="N4"] { background: #1c3641; color: #aae1ea; }
:root[data-theme="space"] .level-badge[data-level="N3"] { background: #332e48; color: #dcc9f5; }
:root[data-theme="space"] .level-badge[data-level="N1"] { background: #422c37; color: #f6c1bb; }
:root[data-theme="space"] .pronunciation { background: #1c3041; border-color: #39576b; color: #b8e9ee; }
:root[data-theme="space"] .pronunciation:hover, :root[data-theme="space"] .pronunciation[data-playing] { background: #284657; border-color: #669caa; }
:root[data-theme="space"] .bookmark { color: #c0c8dc; }
:root[data-theme="space"] .bookmark:hover, :root[data-theme="space"] .bookmark[aria-pressed="true"] { background: #3e352a; color: #f3d89f; }
:root[data-theme="space"] .sense-options button { background: #172236; border-color: var(--rule); }
:root[data-theme="space"] .sense-options button:hover { border-color: #566a87; }
:root[data-theme="space"] .sense-options button[aria-pressed="true"] { color: #f8d6aa; background: #302d31; border-color: #7c6751; }
:root[data-theme="space"] .motion-scene { background: #dadfda; border-color: #455368; color-scheme: light; }
:root[data-theme="space"] .example, :root[data-theme="space"] .contrast-sample {
  background: #1a2538; border-left-color: #b4937c;
}
:root[data-theme="space"] .example h3 { color: #e3c9a9; }
:root[data-theme="space"] .ja-example rt,
:root[data-theme="space"] .study-sentence rt,
:root[data-theme="space"] :is(.contrast-phrase,.contrast-example) rt { color: #97a6bf; font-size: .45em; font-weight: 450; }
:root[data-theme="space"] :is(.ja-example,.study-sentence,.contrast-example) mark {
  color: #ffdaa6; background: linear-gradient(transparent 57%,#77604675 57%); font-weight: 710;
}
:root[data-theme="space"] .ja-example mark rt { color: #b9aa96; }
:root[data-theme="space"] .step:not(:disabled):hover { background: var(--raised); color: var(--ice); }
:root[data-theme="space"] :is(.master,.study-btn.primary,.study-btn.study-play) {
  color: #102b32; background: #a0e2d9; border-color: #a0e2d9;
}
:root[data-theme="space"] :is(.master,.study-btn.primary,.study-btn.study-play):not(:disabled):hover { color: #09262b; background: #baf3e4; border-color: #baf3e4; }
:root[data-theme="space"] .master[aria-pressed="true"] { color: #beedcd; background: #25453c; }
:root[data-theme="space"] .master[aria-pressed="true"]:hover { color: #cef2d8; background: #2b5546; }
:root[data-theme="space"] :is(.catalog-open,.mobile-current) { border-color: #4c656e; background: #1a303c; color: #c2f2e7; }
:root[data-theme="space"] :is(.catalog-open,.mobile-current):hover { color: #e1fff5; background: #26414d; border-color: #719b9e; }
:root[data-theme="space"] .search-icon { color: currentColor; }
:root[data-theme="space"] .level-switch { background: #101a2a; border: 1px solid var(--rule); }
:root[data-theme="space"] .level-switch button { color: #abbad0; }
:root[data-theme="space"] .level-switch button[aria-pressed="true"] { background: #28464b; color: #cdfff2; box-shadow: inset 0 0 0 1px #527f8080; }
:root[data-theme="space"] .level-switch button:not([aria-pressed="true"]):hover { background: #26364a; color: #e5efff; }
:root[data-theme="space"] select:not([multiple]):not([size]) {
  background-color: #142136; border-color: #3d4f68; color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='m2.5 5 4.5 4.5L11.5 5' fill='none' stroke='%23bbcde2' stroke-width='1.65' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
:root[data-theme="space"] select:not([multiple]):not([size]):enabled:hover { border-color: #7991ab; }
:root[data-theme="space"] .catalog, :root[data-theme="space"] .learning-editor { border-color: #48607b; background: #101a2c; box-shadow: 0 20px 75px #020611a6; }
:root[data-theme="space"] dialog::backdrop { background: #030611a8; }
:root[data-theme="space"] .catalog-search { background: #172236; border-color: #4b5e78; color: #bbcce2; }
:root[data-theme="space"] .catalog-search:focus-within { outline-color: var(--ice); }
:root[data-theme="space"] :is(.catalog-more,.catalog-family button) { background: #203047; color: var(--ink); }
:root[data-theme="space"] .catalog-word:hover, :root[data-theme="space"] .catalog-word:focus-visible { background: #1d2c41; }
:root[data-theme="space"] .sheet-grip { background: #596c86; }
:root[data-theme="space"] :is(.learning-textarea,.contrast-search),
:root[data-theme="space"] .study-root input:not([type=checkbox]):not([type=file]),
:root[data-theme="space"] .study-root .study-field > input:not([type=checkbox]):not([type=file]) { background: #152238; border-color: #43546e; }
:root[data-theme="space"] input::placeholder, :root[data-theme="space"] textarea::placeholder { color: #98a8c0; opacity: 1; }
:root[data-theme="space"] .study-btn:not(.primary):not(.study-play):not(.subtle),
:root[data-theme="space"] .contrast-choice { color: var(--ink); background: #19273c; border-color: #3d4e68; }
:root[data-theme="space"] .study-btn:not(.primary):not(.study-play):not(.subtle):not(:disabled):hover,
:root[data-theme="space"] :is(.contrast-choice,.contrast-card):not(:disabled):hover { background: #22374a; border-color: #66868e; }
:root[data-theme="space"] .study-btn.subtle:not(:disabled):hover { background: var(--red-pale); color: var(--ice); }
:root[data-theme="space"] :is(.study-empty,.study-notice,.study-import) { background: #1a273c; }
:root[data-theme="space"] :is(.study-verdict,.contrast-choice.is-answer) { color: #c1edcb; background: #244237; border-color: #53836b; }
:root[data-theme="space"] :is(.study-verdict.wrong,.contrast-choice.is-miss) { color: #ffc8be; background: #432c37; border-color: #a86c75; }
:root[data-theme="space"] .study-verdict.aided { color: #f3d7a7; background: #403727; }
:root[data-theme="space"] .contrast-verdict { color: #a8e2bf; }
:root[data-theme="space"] .contrast-verdict.is-miss { color: #ffb8b0; }
:root[data-theme="space"] .contrast-filter[aria-pressed="true"] { background: var(--red-pale); color: var(--ice); }
:root[data-theme="space"] .contrast-card-arrow { color: #a7b7d3; }
:root[data-theme="space"] .learning-day:hover { background: #192a3d; }
:root[data-theme="space"] .learning-day[aria-pressed="true"] { background: #223249; border-color: #4c627d; }
:root[data-theme="space"] .learning-bar-track { border-color: #486077; }
:root[data-theme="space"] .learning-bar-good, :root[data-theme="space"] .learning-legend-good::before { background-color: #85c9a6; }
:root[data-theme="space"] .learning-bar-aided, :root[data-theme="space"] .learning-legend-aided::before { background-color: #dfb574; }
:root[data-theme="space"] .learning-bar-wrong, :root[data-theme="space"] .learning-legend-wrong::before { background-color: #e19499; }

@media (max-width: 850px) {
  .topbar-inner {
    grid-template-areas: "brand progress switch" "modes modes modes";
    grid-template-columns: minmax(0,1fr) auto auto;
    gap: 0 14px; min-height: auto; padding-top: 9px;
  }
  .brand { grid-area: brand; }
  .completion { grid-area: progress; }
  .theme-switch { grid-area: switch; }
  .topbar-inner .modes {
    grid-area: modes; display: grid; width: 100%; justify-self: stretch;
    grid-template-columns: repeat(4,minmax(0,1fr)); gap: 0;
  }
  .topbar-inner .mode { min-height: 39px; }
  .topbar-inner .mode::after { inset-inline: 14%; }
}
@media (max-width: 590px) {
  .topbar-inner { gap: 0 10px; padding-top: 7px; }
  .brand-mark { width: 31px; height: 31px; border-radius: 9px; }
  .brand-lockup strong { font-size: 15px; }
  .brand-lockup small { font-size: 9px; letter-spacing: .015em; }
  .brand { gap: 7px; }
  .theme-switch button { min-height: 32px; padding: 4px 8px; }
  :root[data-theme="space"] .completion { width: 78px; }
  :root[data-theme="space"] .atlas-tools .map-counts { font-size: 12px; }
  :root[data-theme="space"] .atlas-tools .catalog-open { flex: none; }
  :root[data-theme="space"] .level-switch button { min-width: 33px; padding-inline: 7px; }
  :root[data-theme="space"] .atlas-filters { margin-bottom: 10px; gap: 6px 13px; }
}
@media (max-width: 365px) {
  .topbar-inner { gap: 0 6px; }
  .brand { gap: 5px; }
  .brand-mark { width: 26px; height: 28px; }
  .theme-switch button { padding: 4px 6px; gap: 3px; }
  .topbar-inner .completion, :root[data-theme="space"] .completion { width: 58px; }
  .completion-label { justify-content: flex-end; flex-wrap: wrap; gap: 0 3px; }
  .brand-lockup small { font-size: 8px; }
  :root[data-theme="space"] .atlas-tools .map-counts { font-size: 11px; }
  :root[data-theme="space"] .atlas-tools { gap: 7px; }
  :root[data-theme="space"] .atlas-tools .catalog-open { padding-inline: 8px; gap: 5px; }
}
@media (forced-colors: active) {
  .brand-mark i, .brand-mark::after, .theme-space-icon::before, .theme-city-icon { background: ButtonText; }
  :root[data-theme="space"] select:not([multiple]):not([size]) { background-image: none; border-color: ButtonText; }
  .map-surface[data-map-theme="space"] .station[data-depth][aria-current] { border: 2px solid Highlight; }
  .theme-switch button[aria-pressed="true"] { outline: 1px solid Highlight; }
}

.map-surface[data-map-theme="space"] .station[data-depth] :is(.station-title,.station-gloss) {
  display: block; width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

@media (max-width: 590px) {
  .topbar-inner .completion-label {
    display: grid; justify-content: end; gap: 0;
    font-size: 10px; line-height: 1.2; text-align: right;
  }
  .topbar-inner .completion-label span { display: block; white-space: nowrap; }
  .atlas-tools {display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px;}
  .atlas-tools .map-counts {line-height:1.5;}
}
