:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #111;
  color: #f5f5f2;
}

* { box-sizing: border-box; }

body {
  --sidebar-width: 292px;
  --sidebar-column: var(--sidebar-width);
  margin: 0;
  display: grid;
  grid-template-columns: var(--sidebar-column) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: #111;
  transition: grid-template-columns 0.2s ease;
}

body.sidebar-collapsed { --sidebar-column: 0px; }

#language-sidebar {
  position: relative;
  z-index: 20;
  display: block;
  min-width: 0;
  width: var(--sidebar-width);
  padding: 32px 28px 24px;
  overflow-y: auto;
  background: #191a18;
  border-right: 1px solid #343631;
  transition: transform 0.2s ease;
}

body.sidebar-collapsed #language-sidebar { transform: translateX(-100%); }

.sidebar-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
}

.sidebar-view[hidden] { display: none; }

.sidebar-heading { margin-bottom: 12px; }

.eyebrow {
  margin: 0 0 8px;
  color: #a9c6ba;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.08;
  font-weight: 650;
}

.control-label,
.about-content h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #d9ddd8;
}

#language-picker { position: relative; }

#language-current {
  width: 100%;
  min-height: 44px;
  padding: 0 38px 0 12px;
  border: 1px solid #575b54;
  border-radius: 6px;
  background: #252724;
  color: #fff;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

#language-current::after {
  content: "⌄";
  position: absolute;
  right: 14px;
}

#language-menu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  max-height: min(440px, 60vh);
  overflow: auto;
  border: 1px solid #575b54;
  border-radius: 6px;
  background: #20221f;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

#language-menu[hidden] { display: none; }

.language-actions {
  position: sticky;
  z-index: 1;
  top: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  padding: 6px;
  background: #20221f;
  border-bottom: 1px solid #41443f;
}

.language-actions button,
.language-name {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.language-actions button {
  min-height: 32px;
  border-radius: 4px;
  color: #b6ddcd;
  font-size: 0.72rem;
}

.language-actions button:hover { background: #30332f; }

#language-options {
  margin: 0;
  padding: 4px;
  list-style: none;
}

.language-option {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  min-height: 38px;
  border-radius: 4px;
}

.language-option:hover,
.language-option.is-selected { background: #30332f; }
.language-option.is-disabled { color: #72766f; }

.language-option input {
  width: 16px;
  height: 16px;
  margin: auto;
  accent-color: #8ecab3;
  cursor: pointer;
}

.language-name {
  align-self: stretch;
  padding: 0 8px;
  text-align: left;
}

#language-current:focus-visible,
#sidebar-toggle:focus-visible,
#popup-close:focus-visible,
#help-open:focus-visible,
#help-close:focus-visible,
#about-open:focus-visible,
#about-back:focus-visible,
#navigation-toggle:focus-visible,
.language-actions button:focus-visible,
.language-name:focus-visible,
.definition-toggle:focus-visible {
  outline: 2px solid #9bd3bd;
  outline-offset: 2px;
}

#translation-route {
  margin: -4px 0 0;
  color: #aeb5ad;
  font-size: 0.78rem;
}

.sidebar-navigation,
.sidebar-back {
  display: flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: #b6ddcd;
  font: inherit;
  cursor: pointer;
}

.sidebar-navigation {
  justify-content: space-between;
  width: 100%;
  min-height: 38px;
  padding: 0;
  border-top: 1px solid #353832;
  font-size: 0.78rem;
}

.sidebar-navigation span:last-child { font-size: 1.2rem; }

.sidebar-back {
  align-self: stretch;
  justify-content: flex-start;
  gap: 7px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid #454942;
  border-radius: 5px;
  background: #242623;
  color: #d4eee3;
  font-size: 0.78rem;
  font-weight: 650;
}

.sidebar-back span { font-size: 1.2rem; }

.about-content {
  display: grid;
  gap: 22px;
  padding-top: 4px;
}

.about-content section {
  padding-top: 18px;
  border-top: 1px solid #353832;
}

.about-content p {
  margin: 8px 0 0;
  color: #b9beb7;
  font-size: 0.78rem;
  line-height: 1.6;
}

.about-content a {
  color: #b6ddcd;
  text-underline-offset: 3px;
}

.navigation-legend {
  margin-top: auto;
  border-top: 1px solid #353832;
  border-radius: 5px 5px 0 0;
  transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.navigation-legend.is-pinned {
  border-color: #577668;
  background: #203029;
  box-shadow: inset 3px 0 #8ecab3;
}

.navigation-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #d9ddd8;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.navigation-toggle-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8f9690;
  font-size: 0.62rem;
  font-weight: 650;
  text-transform: uppercase;
}

.navigation-legend.is-open:not(.is-pinned) .navigation-toggle-meta { color: #b6ddcd; }
.navigation-legend.is-pinned .navigation-toggle-meta { color: #bde8d6; }

.navigation-chevron {
  color: #b6ddcd;
  font-size: 1rem;
  transition: transform 0.18s ease;
}

.navigation-legend.is-open .navigation-chevron { transform: rotate(180deg); }

.navigation-panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 0.18s ease, opacity 0.14s ease;
}

.navigation-legend.is-open .navigation-panel {
  grid-template-rows: 1fr;
  opacity: 1;
}

.navigation-panel-inner {
  min-height: 0;
  overflow: hidden;
  padding: 0 8px;
  cursor: pointer;
}

.legend-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
  color: #858b84;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

#help-open {
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: #b6ddcd;
  font: inherit;
  font-size: 0.7rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.navigation-panel dl {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
}

.navigation-panel dl > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.navigation-panel dt,
.navigation-panel dd {
  margin: 0;
  font-size: 0.7rem;
}

.navigation-panel dd {
  display: flex;
  align-items: center;
  gap: 3px;
  color: #d8dcd6;
}

.navigation-panel dl { padding-bottom: 12px; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 21px;
  min-height: 21px;
  padding: 2px 6px 1px;
  border: 1px solid #858b82;
  border-bottom: 3px solid #4a4e48;
  border-radius: 5px;
  background: #30332f;
  color: #f2f4f0;
  font: 700 0.64rem/1 "Segoe UI", Arial, sans-serif;
  box-shadow:
    0 2px 0 #090a09,
    0 3px 5px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

#emotion-container {
  position: relative;
  width: 100%;
  min-width: 0;
  height: 100vh;
  overflow: auto;
  overscroll-behavior: contain;
  background: #111;
  cursor: grab;
  touch-action: none;
}

#emotion-container.is-panning { cursor: grabbing; }

#wheel-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
}

.wheel {
  position: absolute;
  display: block;
}

.wheel path { cursor: inherit; }

.wheel text {
  fill: #111;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  text-anchor: middle;
  dominant-baseline: middle;
  user-select: none;
  cursor: inherit;
}

#sidebar-toggle {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: calc(var(--sidebar-column) - 1px);
  width: 28px;
  height: 72px;
  padding: 0;
  transform: translateY(-50%);
  border: 1px solid #5e625b;
  border-left: 0;
  border-radius: 0 6px 6px 0;
  background: #20221f;
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
  transition: left 0.2s ease;
}

#popup {
  position: fixed;
  z-index: 40;
  top: clamp(24px, 12vh, 128px);
  left: 50%;
  width: min(360px, calc(100vw - 40px));
  padding: 24px 42px 20px 24px;
  transform: translateX(-50%);
  border: 3px solid #222;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  color: #111;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  text-align: center;
}

#popup[hidden] { display: none; }

#popup-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #111;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

#popup-label {
  overflow-wrap: anywhere;
  font-size: 1.35rem;
  font-weight: 700;
}

#popup-english {
  margin-top: 7px;
  color: #5a5d58;
  font-size: 0.82rem;
}

#popup-scroll-hint {
  margin: 10px 0 0;
  color: #777b74;
  font-size: 0.7rem;
}

#definition-disclosures {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #d7d9d4;
}

.definition-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  margin-top: 6px;
  padding: 6px 10px;
  border: 1px solid #b8bbb5;
  border-radius: 4px;
  background: #f4f5f1;
  color: #454842;
  font: inherit;
  font-size: 0.72rem;
  text-align: left;
  cursor: pointer;
}

.definition-toggle[aria-expanded="true"] {
  border-color: #4f7464;
  background: #dcebe4;
  color: #1f3b30;
}

.definition-toggle:disabled {
  opacity: 0.48;
  cursor: default;
}

.definition-symbol {
  flex: 0 0 auto;
  width: 1.1em;
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.definition-panel {
  padding: 10px 10px 4px;
}

.definition-panel[hidden] { display: none; }

.definition-panel p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: left;
}

.wheel path.is-active {
  stroke: #fff;
  stroke-width: 3;
  stroke-linejoin: bevel;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.9));
}

#help-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 28px;
  overflow-y: auto;
  border: 1px solid #656a62;
  border-radius: 8px;
  background: #20221f;
  color: #f5f5f2;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

#help-dialog::backdrop { background: rgba(0, 0, 0, 0.68); }

#help-dialog h2 {
  margin: 0 40px 22px 0;
  font-size: 1.25rem;
}

#help-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
}

.help-controls {
  display: grid;
  gap: 0;
  margin: 0;
}

.help-controls > div {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 18px;
  padding: 12px 0;
  border-top: 1px solid #3d403b;
}

.help-controls dt { font-weight: 700; }
.help-controls dd { margin: 0; color: #c4c9c2; line-height: 1.5; }

.wheel text.is-active { font-weight: 800; }

@media (max-width: 760px) {
  body {
    --sidebar-width: min(292px, calc(100vw - 48px));
    display: block;
  }

  #emotion-container {
    height: 100vh;
    padding: 48px 0 0;
  }

  #language-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    box-shadow: 18px 0 50px rgba(0, 0, 0, 0.4);
  }

  body:not(.sidebar-collapsed) #language-sidebar { transform: translateX(0); }
}

@media (max-width: 520px) {
  #help-dialog { padding: 24px 20px; }

  .help-controls > div {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media print {
  @page { size: landscape; margin: 0.3in; }

  :root,
  body {
    width: 100%;
    height: auto;
    overflow: visible;
    background: #fff;
  }

  body { display: block; }

  #language-sidebar,
  #sidebar-toggle,
  #popup,
  #help-dialog {
    display: none !important;
  }

  #emotion-container {
    width: 100%;
    height: 7.4in;
    overflow: hidden;
    background: #fff;
  }

  #wheel-stage {
    width: 7.4in !important;
    height: 7.4in !important;
    min-width: 0;
    min-height: 0;
    margin: 0 auto;
  }

  #wheel {
    position: static;
    width: 7.4in !important;
    height: 7.4in !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
