:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #697386;
  --line: #dce2ea;
  --paper: #fbfcfe;
  --panel: #ffffff;
  --green: #4fa85a;
  --blue: #2f6fcf;
  --coral: #d9694b;
  --gold: #d3a62c;
  --rose: #b24f66;
  --shadow: 0 18px 45px rgba(31, 42, 68, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(79, 168, 90, 0.18), transparent 24%),
    linear-gradient(135deg, #eef7f1 0%, #f8fafc 45%, #f4f0ea 100%);
  color: var(--ink);
  font-family:
    "Segoe UI",
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 24px;
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.sidebar,
.workspace,
.entry-form,
.backup-panel,
.review-panel {
  border: 1px solid rgba(220, 226, 234, 0.9);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  display: grid;
  gap: 24px;
  padding: 24px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 10px;
}

h3 {
  margin-bottom: 6px;
}

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

.stats-grid article {
  min-height: 94px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.stats-grid span {
  display: block;
  color: var(--blue);
  font-size: 2rem;
  font-weight: 800;
}

.stats-grid p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab,
.primary-action,
.secondary-action,
.backup-actions button,
.file-button,
.review-actions button,
.card-actions button,
.ink-actions button,
.translation-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.tab.is-active,
.primary-action {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.secondary-action {
  border-color: rgba(47, 111, 207, 0.28);
  background: #f4f8ff;
  color: var(--blue);
}

.workspace {
  min-height: calc(100vh - 64px);
  padding: 24px;
  border-radius: 8px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.entry-form {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: 8px;
}

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

.form-row.compact {
  grid-template-columns: repeat(2, minmax(180px, 260px));
}

.form-row.compact.triple {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 207, 0.12);
}

input.is-locked {
  background: #f4f7fb;
  color: #5b6578;
  border-style: dashed;
}

.mode-hint,
.translation-help {
  margin: -4px 0 0;
  padding: 12px 14px;
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: #f5f8ff;
  color: var(--muted);
  font-size: 0.92rem;
}

.handwriting-panel,
.translation-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: 8px;
}

.handwriting-panel {
  border: 1px solid rgba(79, 168, 90, 0.25);
  background:
    linear-gradient(180deg, rgba(79, 168, 90, 0.08), transparent 58%),
    #fdfefb;
}

.translation-panel {
  border: 1px solid rgba(47, 111, 207, 0.18);
  background:
    linear-gradient(180deg, rgba(47, 111, 207, 0.06), transparent 48%),
    #fbfdff;
}

.handwriting-header,
.translation-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.ocr-status,
.translation-status {
  margin: 0;
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 700;
}

.ocr-status {
  max-width: 280px;
  text-align: right;
}

.translation-settings {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 0.9fr;
  gap: 12px;
}

.ink-card,
.translation-draft {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.ink-card-header,
.translation-draft-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.ink-card-header p,
.translation-draft-note {
  margin: 0;
  color: var(--muted);
}

.ink-language {
  margin: 0;
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 700;
}

.ink-canvas {
  width: 100%;
  height: 240px;
  border: 1px solid rgba(47, 111, 207, 0.18);
  border-radius: 8px;
  background: #fffdf8;
  touch-action: none;
}

.ink-actions,
.translation-actions,
.card-actions,
.review-actions,
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.translation-draft-text {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.6;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 12px;
  margin: 18px 0;
}

.card-list {
  display: grid;
  gap: 12px;
}

.archive-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.archive-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.source-text {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 800;
}

.meaning-text {
  margin: 0;
  color: var(--muted);
}

.meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eff4fb;
  color: #2b528a;
  font-size: 0.82rem;
  font-weight: 700;
}

.chip.word {
  background: #edf7ef;
  color: #2f7540;
}

.chip.due {
  background: #fff4de;
  color: #8b6514;
}

.chip.type {
  background: #eef1ff;
  color: #4454a3;
}

.chip.capture {
  background: #fff1f4;
  color: var(--rose);
}

.chip.language {
  background: #eef8ff;
  color: #245a8c;
}

.chip.ai {
  background: #fdf4ea;
  color: #9b5c18;
}

.note-text {
  margin: 0;
  padding-left: 12px;
  border-left: 3px solid var(--gold);
  color: var(--muted);
}

.card-actions button,
.review-actions button,
.backup-actions button,
.ink-actions button,
.translation-actions button,
.file-button {
  padding: 0 14px;
}

.danger {
  color: var(--coral) !important;
}

.review-panel,
.backup-panel {
  padding: 24px;
  border-radius: 8px;
}

.review-card {
  display: grid;
  gap: 18px;
}

.review-source {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 3rem);
  font-weight: 800;
  line-height: 1.15;
}

.review-answer {
  display: none;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.review-answer.is-visible {
  display: block;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

#dataPreview {
  margin-top: 16px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.85rem;
}

.empty-state {
  padding: 36px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
}

.empty-state p,
.backup-panel p {
  color: var(--muted);
}

@media (max-width: 980px) {
  .translation-settings,
  .form-row.compact.triple {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px 0;
  }

  .sidebar {
    position: static;
  }

  .form-row,
  .toolbar,
  .form-row.compact {
    grid-template-columns: 1fr;
  }

  .handwriting-header,
  .translation-header,
  .ink-card-header,
  .translation-draft-header {
    display: grid;
  }

  .ocr-status {
    max-width: none;
    text-align: left;
  }
}
