:root {
  --page-width: 297mm;
  --canvas: #e8edf0;
  --panel: #ffffff;
  --panel-soft: #f4f7f8;
  --ink: #131a20;
  --muted: #66727a;
  --line: #cbd4d8;
  --dark: #111820;
  --dark-soft: #19232c;
  --cyan: #00a8ba;
  --cyan-dark: #007f8d;
  --mint: #29a976;
  --coral: #e35d52;
  --yellow: #f1b83b;
  --rose: #c94057;
  --shadow: 0 18px 46px rgba(19, 26, 32, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(0, 168, 186, 0.3);
  outline-offset: 2px;
}

.app-header {
  width: min(var(--page-width), calc(100% - 32px));
  min-height: 112px;
  margin: 0 auto;
  padding: 24px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

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

.brand-mark {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid #263440;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 10px 24px rgba(17, 24, 32, 0.2);
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan-dark);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.72rem;
  line-height: 1.15;
}

.owner-line {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.owner-line strong {
  color: var(--coral);
  font-weight: 850;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.stats {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.stat {
  min-width: 86px;
  height: 48px;
  padding: 6px 12px;
  border-left: 3px solid var(--cyan);
  background: rgba(255, 255, 255, 0.7);
  display: grid;
  align-content: center;
}

.stat:nth-child(2) {
  border-left-color: var(--coral);
}

.stat strong,
.stat small {
  display: block;
}

.stat strong {
  color: var(--ink);
  font-size: 0.94rem;
}

.stat small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.68rem;
}

.status-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(41, 169, 118, 0.34);
  border-radius: 999px;
  background: #e7f7ef;
  color: #16724e;
  padding: 0 13px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: currentColor;
}

.workspace {
  width: min(var(--page-width), calc(100% - 32px));
  margin: 0 auto 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.pane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.input-pane {
  min-height: 400px;
  border-color: #25313b;
  background: var(--dark);
}

.output-pane {
  min-height: 520px;
}

.pane-toolbar {
  min-height: 62px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.input-pane .pane-toolbar {
  border-bottom-color: #2a3742;
  color: #f5f8fa;
}

.pane-title,
.toolbar-actions,
.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-number {
  min-width: 28px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 4px;
  color: var(--coral);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  font-weight: 900;
}

.output-pane .step-number {
  color: var(--cyan-dark);
}

.ghost-button,
.primary-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 800;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.input-pane .ghost-button {
  border-color: #3b4a56;
  background: #1b2630;
  color: #dce5e9;
}

.ghost-button:hover {
  border-color: var(--cyan);
  color: var(--cyan-dark);
}

.input-pane .ghost-button:hover {
  color: #54d8e4;
}

.primary-button {
  min-width: 132px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--cyan);
  color: #071b1e;
  box-shadow: 0 8px 20px rgba(0, 168, 186, 0.22);
}

.primary-button span {
  color: #fff;
  font-size: 1.1rem;
}

.primary-button:hover {
  background: #28c0ce;
  transform: translateY(-1px);
}

#articleInput {
  width: 100%;
  flex: 1;
  min-height: 270px;
  border: 0;
  resize: vertical;
  padding: 24px;
  color: #e9f0f2;
  background: var(--dark);
  caret-color: #50dbe6;
  line-height: 1.72;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.96rem;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}

#articleInput::placeholder {
  color: #71818d;
}

#articleInput:focus {
  background: #131d25;
  box-shadow: inset 3px 0 0 var(--cyan);
}

.control-row {
  min-height: 70px;
  padding: 14px 18px;
  border-top: 1px solid #2a3742;
  justify-content: space-between;
  background: var(--dark-soft);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #aebbc3;
  white-space: nowrap;
}

.switch-label {
  display: grid;
}

.switch-label strong {
  color: #edf3f5;
  font-size: 0.83rem;
}

.switch-label small {
  margin-top: 2px;
  color: #82919b;
  font-size: 0.68rem;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  width: 42px;
  height: 24px;
  border: 1px solid #52616c;
  border-radius: 999px;
  background: #35434e;
  position: relative;
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-ui::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e6edef;
  position: absolute;
  left: 3px;
  top: 3px;
  transition: transform 160ms ease;
}

.switch input:checked + .switch-ui {
  border-color: var(--mint);
  background: var(--mint);
}

.switch input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.source-indicator {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.source-indicator i {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 3px rgba(41, 169, 118, 0.13);
}

.annotated {
  --reader-row-height: 78px;
  flex: 1;
  padding: 0 38px;
  background-color: #fff;
  background-image: repeating-linear-gradient(
    to bottom,
    #dfe6e8 0,
    #dfe6e8 1px,
    transparent 1px,
    transparent var(--reader-row-height)
  );
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  line-height: var(--reader-row-height);
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: anywhere;
  word-break: normal;
}

.annotated.empty {
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  display: grid;
  place-items: center;
  text-align: center;
}

.annotated ruby {
  ruby-align: center;
  ruby-position: over;
  margin-inline: 2px;
  white-space: nowrap;
}

.annotated .word-unit {
  display: inline-block;
  white-space: nowrap;
  break-inside: avoid;
  overflow-wrap: normal;
  word-break: keep-all;
}

.annotated rt {
  color: var(--cyan-dark);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.85rem;
  font-weight: 850;
  line-height: 1.1;
  text-align: center;
}

.annotated ruby.pending rt {
  color: #9a6500;
}

.annotated ruby.unknown rt {
  color: var(--rose);
}

.annotated ruby.local rt {
  color: var(--cyan-dark);
}

.annotated ruby.online rt {
  color: #3565b4;
}

.annotated ruby.backup rt {
  color: #9a6500;
}

.toast {
  color: var(--cyan-dark);
}

@media (max-width: 860px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
    justify-content: flex-start;
  }

  .input-pane {
    min-height: 400px;
  }

  .output-pane {
    min-height: 480px;
  }

  #articleInput {
    min-height: 280px;
  }
}

@media (max-width: 560px) {
  .app-header,
  .workspace {
    width: min(var(--page-width), calc(100% - 20px));
  }

  .app-header {
    min-height: auto;
    padding-top: 18px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
  }

  h1 {
    font-size: 1.38rem;
  }

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

  .status-pill {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .pane-toolbar,
  .control-row {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions,
  .control-row {
    width: 100%;
  }

  .toolbar-actions {
    justify-content: space-between;
  }

  .source-indicator {
    flex: 1 1 auto;
    font-size: 0.7rem;
  }

  .output-pane .ghost-button {
    flex: 0 0 auto;
  }

  .switch {
    white-space: normal;
  }

  .ghost-button,
  .primary-button {
    flex: 1;
  }

  .annotated {
    --reader-row-height: 72px;
    padding: 0 20px;
    font-size: 1.12rem;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 12mm;
  }

  body {
    background: #fff;
  }

  .app-header,
  .workspace {
    width: 100%;
  }

  .input-pane,
  .app-header .stats {
    display: none;
  }

  .pane {
    box-shadow: none;
  }

  .annotated {
    background-image: none;
  }
}
