:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-alt: #eef3f1;
  --text: #202426;
  --muted: #67706d;
  --line: #d9ded9;
  --accent: #1f7a68;
  --accent-strong: #165c50;
  --accent-soft: #dcece7;
  --danger: #a53a3a;
  --shadow: 0 14px 36px rgba(41, 49, 47, 0.09);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 28px 28px 96px;
}

.workspace {
  width: min(1380px, 100%);
  margin: 0 auto;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  font-weight: 760;
}

h2 {
  font-size: 16px;
  font-weight: 720;
}

.topbar p,
.note,
.message {
  color: var(--muted);
}

.topbar p {
  margin-top: 6px;
}

.status-pill {
  min-width: 172px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.status-pill.ready {
  border-color: #8cc7b8;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.anki-status {
  width: fit-content;
  min-width: 220px;
}

.anki-options {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(240px, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.layout {
  display: block;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-panel,
.editor-panel,
.output-panel {
  padding: 18px;
}

.settings-modal[hidden] {
  display: none;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 36, 38, 0.34);
}

.settings-dialog {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
}

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

.compact-head {
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 13px;
}

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

input {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 360px;
  padding: 14px;
  line-height: 1.55;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: #79b7aa;
  box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.12);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.button-row.wrap {
  flex-wrap: wrap;
  margin-top: 14px;
}

.button-row.compact {
  gap: 8px;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

button.secondary {
  border-color: var(--line);
  background: var(--surface-alt);
  color: var(--text);
}

button.secondary:hover {
  border-color: #bfc9c4;
  background: #e4ece8;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface-alt);
  color: var(--text);
}

.note {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.5;
}

.settings-divider {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.section-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.cloud-inputs,
.cloud-study-list {
  max-height: 260px;
  margin-top: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.cloud-study-list {
  max-height: 520px;
}

.cloud-input-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.cloud-input-item + .cloud-input-item {
  margin-top: 8px;
}

.cloud-input-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cloud-input-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.cloud-input-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.message {
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid #8cc7b8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 40px rgba(32, 36, 38, 0.16);
  font-size: 13px;
  line-height: 1.45;
}

.message.error {
  border-color: #e0a1a1;
  background: #fff6f6;
  color: var(--danger);
}

.floating-message {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: min(420px, calc(100vw - 48px));
  max-height: min(220px, calc(100vh - 48px));
  overflow: auto;
}

.floating-message:empty {
  display: none;
}

.output-panel {
  margin-top: 18px;
}

#markdownOutput,
#htmlOutput {
  min-height: 430px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

#htmlOutput {
  min-height: 260px;
  margin-top: 14px;
}

.html-preview {
  min-height: 220px;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 14px;
}

.html-preview.editing {
  border-color: #79b7aa;
  background: #f8fcfa;
  box-shadow: inset 0 0 0 2px rgba(31, 122, 104, 0.08);
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.study-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.study-table th,
.study-table td {
  border: 1px solid #d7ddd8;
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.study-table th {
  background: var(--surface-alt);
  font-weight: 720;
}

.study-table td[contenteditable="true"] {
  background: #fffef8;
  outline: none;
}

.study-table td[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 2px rgba(31, 122, 104, 0.22);
}

.study-table .row-actions {
  width: 86px;
  text-align: center;
}

.delete-row-button {
  min-height: 32px;
  padding: 0 10px;
  border-color: #e0a1a1;
  background: #fff6f6;
  color: var(--danger);
  font-size: 12px;
}

.delete-row-button:hover {
  border-color: #cf7e7e;
  background: #ffecec;
}

.study-table ruby {
  ruby-align: center;
}

.study-table rt {
  color: #6c5f52;
  font-size: 0.62em;
  line-height: 1;
}

.study-table .jp {
  font-size: 18px;
  line-height: 2;
}

.term {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.8;
}

.meaning {
  font-weight: 700;
  margin-bottom: 8px;
}

.examples {
  margin: 8px 0 0;
  padding-left: 1.15em;
  color: #4d5653;
  font-size: 0.92em;
  line-height: 1.7;
}

.examples li + li {
  margin-top: 4px;
}

.examples::before {
  content: "例句";
  display: block;
  margin-left: -1.15em;
  color: #6f7a76;
  font-size: 0.82em;
  font-weight: 700;
}

.subsection {
  margin-top: 10px;
  color: #4d5653;
  font-size: 0.92em;
  line-height: 1.7;
}

.grammar-notes {
  margin: 4px 0 0;
  padding-left: 1.15em;
}

.saved-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
}

.saved-list {
  min-height: 360px;
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px;
}

.saved-file-button {
  display: block;
  width: 100%;
  min-height: 38px;
  margin-bottom: 8px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  overflow-wrap: anywhere;
}

.saved-file-button:hover,
.saved-file-button.active {
  border-color: #8cc7b8;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.saved-viewer {
  width: 100%;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 18px 18px 104px;
  }

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

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .settings-modal {
    align-items: stretch;
    padding: 16px;
  }

  .settings-dialog {
    width: 100%;
    max-height: calc(100vh - 32px);
  }

  .status-pill {
    width: 100%;
  }

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

  .anki-options {
    grid-template-columns: 1fr;
  }

  .floating-message {
    right: 16px;
    bottom: 16px;
    width: calc(100vw - 32px);
  }
}
