:root {
  --bg: #f7f8f4;
  --paper: #ffffff;
  --ink: #17201c;
  --muted: #69736e;
  --line: #dce2dc;
  --accent: #126b63;
  --accent-2: #d64f3a;
  --accent-soft: #e7f5f2;
  --gold: #d9a441;
  --shadow: 0 14px 44px rgba(32, 43, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(18, 107, 99, 0.08), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(14px, 4vw, 42px);
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(247, 248, 244, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  background: var(--accent);
  color: white;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 4px 4px 0 var(--gold);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
}

.brand p,
footer,
.panel-head span {
  color: var(--muted);
}

.top-actions,
.compact-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 0 clamp(14px, 4vw, 42px) 86px;
}

.workspace {
  display: grid;
  gap: 18px;
}

.editor-panel,
.reader-panel,
.control-group,
dialog {
  background: rgba(255, 253, 248, 0.93);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.editor-panel,
.reader-panel {
  min-height: 0;
}

.panel-head,
.group-title,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.control-group h2,
.dialog-head h2 {
  font-size: 16px;
}

textarea {
  width: 100%;
  min-height: 230px;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 16px;
  background: transparent;
  color: var(--ink);
  line-height: 1.8;
}

.scan-box {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.scan-box span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.scan-button {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.scan-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.image-preview {
  padding: 10px 14px 0;
}

.image-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f6f3;
}

.reader {
  min-height: 256px;
  padding: 14px;
  line-height: 1.8;
  font-size: 16px;
}

.reader.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.sentence-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.sentence-card:hover {
  border-color: #accfc8;
  transform: translateY(-1px);
}

.sentence-card.mixed {
  background: var(--accent-soft);
  border-color: #b9ddd6;
}

.sentence {
  display: block;
  padding: 0;
  margin: 0;
  border-radius: 0;
  transition: background 0.18s ease, color 0.18s ease;
}

.term {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 5px;
  background: white;
  color: var(--accent);
  border: 1px solid #aed8d0;
  font-weight: 800;
  vertical-align: baseline;
}

.term small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
  font-weight: 700;
}

.reader.focus .sentence-card:not(.mixed) {
  color: #8a8c86;
}

.reader.focus .sentence-card.mixed {
  background: #d7eee6;
  color: #073b32;
}

.sentence-note {
  color: var(--accent);
  font-weight: 700;
  line-height: 1.6;
}

.full-translation {
  font-weight: 750;
  color: #0b5b51;
}

.term-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.term-card,
.review-chip {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 10px;
  border: 1px solid #b9ddd6;
  border-radius: 8px;
  background: white;
}

.term-card strong,
.review-chip {
  color: var(--accent);
  font-weight: 900;
}

.term-card small {
  color: var(--muted);
  font-size: 12px;
}

.term-card span,
.review-chip span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.review-only {
  display: grid;
  gap: 8px;
}

.review-chip {
  width: 100%;
  text-align: left;
  min-height: 54px;
}

.blur-ja .original,
.hide-ja .original {
  color: transparent;
  text-shadow: 0 0 8px rgba(23, 32, 28, 0.42);
  user-select: none;
}

.hide-ja .gloss {
  color: transparent;
  text-shadow: 0 0 8px rgba(23, 32, 28, 0.38);
}

.gloss {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.gloss.hidden {
  display: none;
}

.controls {
  display: grid;
  gap: 14px;
  align-content: start;
}

.control-group {
  padding: 16px;
}

.control-group h2 {
  margin-bottom: 12px;
}

.field,
.range-field,
.check {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  border-radius: 8px;
}

.range-field input {
  accent-color: var(--accent);
}

.check {
  grid-template-columns: 20px 1fr;
  align-items: center;
  color: var(--ink);
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #ece5d8;
  padding: 5px;
  border-radius: 8px;
}

.segmented button,
.ghost,
.primary,
.secondary,
.icon-button,
.link-button {
  min-height: 40px;
  border-radius: 6px;
}

.segmented button {
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(36, 42, 35, 0.08);
}

.primary {
  background: var(--accent);
  color: white;
  padding: 0 18px;
  font-weight: 700;
}

.secondary {
  background: var(--ink);
  color: white;
  padding: 0 14px;
}

.ghost {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 0 14px;
}

.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.full {
  width: 100%;
  margin-top: 12px;
}

.icon-button {
  width: 40px;
  background: #efe7da;
  color: var(--ink);
  font-size: 22px;
}

.link-button {
  background: transparent;
  color: var(--accent-2);
  padding: 0;
  min-height: auto;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 250px;
  overflow: auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats div {
  display: grid;
  gap: 2px;
  padding: 12px;
  background: #f2f7f4;
  border-radius: 8px;
  text-align: center;
}

.stats strong {
  font-size: 22px;
  color: var(--accent);
}

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

.history-item {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 10px;
  background: #f8f3ea;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
}

.history-item:hover {
  border-color: var(--gold);
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
}

dialog {
  width: min(680px, calc(100vw - 28px));
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(31, 37, 32, 0.42);
}

dialog form {
  padding: 0 0 16px;
}

.quiz-body {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.quiz-card {
  padding: 14px;
  background: #f8f3ea;
  border-left: 4px solid var(--accent);
  line-height: 1.7;
}

.quiz-source {
  margin: 8px 0 10px;
  color: var(--muted);
}

.choice-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.choice {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
}

.choice.correct {
  border-color: #188765;
  background: #dcf4ec;
  color: #0b6047;
}

.choice.wrong {
  border-color: #d65a4b;
  background: #fae4df;
  color: #9f2f22;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 0 clamp(14px, 4vw, 42px) 24px;
  font-size: 12px;
}

.bottom-bar {
  display: none;
}

@media (max-width: 900px) {
  .topbar,
  .layout,
  footer {
    grid-template-columns: 1fr;
  }

  .topbar,
  footer {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .layout {
    display: grid;
    grid-template-columns: 1fr;
  }

}

@media (max-width: 560px) {
  body {
    background: var(--bg);
  }

  .topbar {
    padding: 10px 12px;
  }

  .brand {
    gap: 10px;
  }

  .mark {
    width: 40px;
    height: 40px;
  }

  h1 {
    font-size: 21px;
  }

  .brand p {
    font-size: 12px;
  }

  .top-actions {
    display: none;
  }

  .layout {
    padding: 0 10px 92px;
    gap: 12px;
  }

  .control-group,
  .editor-panel,
  .reader-panel {
    border-radius: 9px;
    box-shadow: 0 8px 28px rgba(32, 43, 38, 0.08);
  }

  .mobile-priority {
    padding: 12px;
  }

  .controls {
    gap: 10px;
  }

  .control-group {
    padding: 12px;
  }

  textarea {
    min-height: 150px;
    padding: 14px;
  }

  .reader-head,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .compact-actions {
    width: 100%;
  }

  .compact-actions button {
    flex: 1;
  }

  .reader {
    font-size: 16px;
    padding: 10px;
  }

  .sentence-card {
    padding: 13px;
    margin-bottom: 9px;
  }

  .term-grid {
    grid-template-columns: 1fr;
  }

  .history-group {
    display: none;
  }

  footer {
    display: none;
  }

  .bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr 1.3fr 1fr;
    gap: 8px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(247, 248, 244, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }

  .bottom-bar button {
    min-height: 48px;
  }

  .choice-list {
    grid-template-columns: 1fr;
  }
}
