:root {
  --porcelain: #f5f7f1;
  --paper: #fbfcf8;
  --ink: #13201c;
  --muted: #6e7a72;
  --celadon: #b9ccc4;
  --mineral: #326b5a;
  --blueprint: #2f5f7f;
  --copper: #c96c4a;
  --line: #dfe7df;
  --shadow: 0 18px 50px rgba(28, 44, 38, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--porcelain);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(185, 204, 196, 0.28) 1px, transparent 1px) 0 0 / 42px 42px,
    var(--porcelain);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}

button:hover {
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(201, 108, 74, 0.34);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.memory-rail {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 0;
  width: 68px;
  border-right: 1px solid var(--line);
  background: rgba(251, 252, 248, 0.52);
}

.rail-label {
  position: absolute;
  top: 28px;
  left: 22px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0;
  text-orientation: mixed;
  text-transform: uppercase;
  writing-mode: vertical-rl;
}

.rail-line {
  position: absolute;
  top: 142px;
  bottom: 40px;
  left: 33px;
  width: 2px;
  background: var(--celadon);
}

.rail-marker {
  position: absolute;
  left: 50%;
  width: 13px;
  height: 13px;
  border: 2px solid var(--paper);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px var(--line);
}

.rail-marker.new {
  background: var(--copper);
}

.rail-marker.learning {
  background: var(--blueprint);
}

.rail-marker.mastered {
  background: var(--mineral);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100vw - 112px));
  margin: 0 auto;
  padding: 34px 0 44px;
}

.topbar,
.summary-band,
.controls,
.workspace {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.token-panel {
  display: grid;
  grid-template-columns: minmax(180px, 260px) auto auto;
  gap: 8px;
  align-items: end;
  max-width: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(251, 252, 248, 0.78);
  box-shadow: 0 8px 26px rgba(28, 44, 38, 0.08);
}

.token-panel label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.token-panel label span {
  color: var(--muted);
  font-size: 12px;
}

.token-panel input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
}

.token-panel small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.token-panel small.is-ready {
  color: var(--mineral);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", "Iowan Old Style", Georgia, serif;
  font-size: clamp(32px, 5vw, 60px);
  font-weight: 700;
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", "Iowan Old Style", Georgia, serif;
  font-size: 24px;
}

.ghost-button {
  border-color: var(--line);
  background: var(--paper);
  color: var(--ink);
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 140px)) minmax(260px, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 252, 248, 0.78);
  box-shadow: var(--shadow);
}

.summary-item {
  min-height: 78px;
  border-left: 4px solid var(--celadon);
  padding: 10px 10px 8px 14px;
  background: var(--paper);
}

.summary-item:nth-child(2) {
  border-left-color: var(--blueprint);
}

.summary-item:nth-child(3) {
  border-left-color: var(--mineral);
}

.summary-item span {
  display: block;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 30px;
  line-height: 1;
}

.summary-item small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
}

.quick-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.quick-add input,
.search-box input,
.detail-note textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.quick-add input,
.search-box input {
  min-height: 42px;
  padding: 0 13px;
}

.controls {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.search-box {
  display: grid;
  grid-template-columns: auto minmax(160px, 280px);
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px 0 14px;
  background: rgba(251, 252, 248, 0.78);
}

.search-box span {
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  border-color: transparent;
  background: transparent;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(76px, 1fr));
  gap: 4px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: rgba(251, 252, 248, 0.78);
}

.segmented button {
  min-height: 36px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--ink);
  color: var(--paper);
}

.notice {
  margin: 0 0 16px;
  border: 1px solid rgba(201, 108, 74, 0.32);
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff4ee;
  color: #7c3f2d;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.word-list {
  display: grid;
  gap: 10px;
}

.word-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  min-height: 94px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--celadon);
  border-radius: 8px;
  padding: 13px;
  background: rgba(251, 252, 248, 0.86);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.word-card > span:first-child {
  min-width: 0;
}

.word-card.active {
  border-color: rgba(19, 32, 28, 0.42);
  border-left-color: var(--ink);
  box-shadow: 0 8px 28px rgba(28, 44, 38, 0.1);
}

.word-card.learning {
  border-left-color: var(--blueprint);
}

.word-card.mastered {
  border-left-color: var(--mineral);
}

.word-card strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 22px;
  line-height: 1.05;
  white-space: nowrap;
}

.word-card em {
  display: -webkit-box;
  margin-top: 8px;
  overflow: hidden;
  color: var(--muted);
  font-style: normal;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  align-self: start;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.detail-pane {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: rgba(251, 252, 248, 0.9);
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--muted);
  text-align: center;
}

.detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.detail-heading > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.detail-title {
  margin-bottom: 8px;
  max-width: 100%;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-family: "Songti SC", "Noto Serif CJK SC", "Iowan Old Style", Georgia, serif;
  font-size: clamp(34px, 5vw, 62px);
  line-height: 0.98;
  white-space: nowrap;
}

.detail-translation {
  margin: 0;
  color: var(--mineral);
  font-size: 19px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.danger-button {
  border-color: #bf5a3c;
  background: #bf5a3c;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.detail-block {
  border-top: 3px solid var(--celadon);
  padding-top: 12px;
}

.detail-block.full {
  grid-column: 1 / -1;
}

.detail-block h3 {
  margin-bottom: 8px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.detail-block p {
  margin-bottom: 0;
  line-height: 1.7;
}

.capture-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.capture-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--paper);
}

.capture-list a {
  color: var(--blueprint);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.capture-list small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.detail-note {
  display: grid;
  gap: 9px;
}

.detail-note textarea {
  min-height: 92px;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.5;
}

@media (max-width: 900px) {
  .memory-rail {
    display: none;
  }

  .app-shell {
    width: min(100% - 28px, 760px);
  }

  .summary-band {
    grid-template-columns: repeat(3, 1fr);
  }

  .quick-add {
    grid-column: 1 / -1;
  }

  .controls,
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .controls,
  .topbar {
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .token-panel {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 460px);
    padding-top: 22px;
  }

  .summary-band,
  .detail-grid,
  .segmented {
    grid-template-columns: 1fr;
  }

  .search-box {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .token-panel {
    grid-template-columns: 1fr;
  }

  .detail-heading {
    flex-direction: column;
  }

  .detail-actions {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
