:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d8dee8;
  --line-strong: #b8c2cf;
  --ink: #17202a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-strong: #155e75;
  --accent-soft: #e6f5f3;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --focus: rgba(15, 118, 110, 0.22);
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  padding: 16px;
}

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

button,
a,
input,
select,
textarea {
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background-color 0.16s ease,
    color 0.16s ease;
}

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

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 28px;
  line-height: 1.15;
}

h3 {
  line-height: 1.25;
}

.eyebrow,
.section-label,
.detail-type,
.viewer-hint,
.status-text,
.helper-text,
.item-time,
.item-source,
.item-notes,
.word-chip-translation,
.word-chip-time,
.word-phonetic {
  color: var(--muted);
  font-size: 12px;
}

.eyebrow,
.section-label,
.detail-type,
.viewer-hint {
  text-transform: uppercase;
}

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 32px);
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: #102a43;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.field-grid,
.type-grid,
.form-actions,
.toolbar,
.toolbar-actions,
.board,
.item-card-top,
.detail-header,
.detail-actions,
.viewer-top,
.meta-grid,
.upload-row,
.stored-row,
.asset-head,
.field-title-row,
.wordbook-list-head,
.word-main-row,
.viewer-actions,
.wordbook-head,
.word-result-actions {
  display: flex;
}

.type-grid,
.form-actions,
.upload-row,
.stored-row,
.detail-actions,
.viewer-actions,
.word-result-actions {
  gap: 8px;
}

.pill-option {
  flex: 1;
  cursor: pointer;
}

.pill-option input {
  display: none;
}

.pill-option span {
  display: block;
  padding: 9px 10px;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
}

.pill-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.field,
.asset-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.field-title-row > span,
.asset-head strong {
  font-size: 13px;
}

.asset-card,
.meta-card,
.notes-card,
.viewer-card,
.wordbook-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.asset-card {
  padding: 12px;
}

.field input,
.field textarea,
.toolbar-filters input,
.toolbar-filters select,
.stored-row select,
.word-search-form input,
.word-history-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.field input:focus,
.field textarea:focus,
.toolbar-filters input:focus,
.toolbar-filters select:focus,
.stored-row select:focus,
.word-search-form input:focus,
.word-history-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.hidden-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-row .primary-btn {
  width: 100%;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.link-btn,
.icon-link {
  min-height: 38px;
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  white-space: nowrap;
}

.small-btn {
  min-height: 32px;
  padding: 7px 10px;
}

.primary-btn {
  background: var(--accent);
  color: #ffffff;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.ghost-btn,
.icon-link {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-btn:hover,
.icon-link:hover {
  border-color: var(--line-strong);
  background: #f1f5f9;
}

.wordbook-toggle.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.icon-link.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.danger-btn {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #ffccc7;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.toolbar {
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 4px 2px;
}

.toolbar-actions {
  align-items: center;
  gap: 10px;
}

.toolbar-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 160px;
  gap: 8px;
}

.wordbook-wrap {
  position: static;
}

.wordbook-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(420px, calc(100vw - 24px));
  height: 100dvh;
  padding: 16px;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-radius: 0;
  background: #ffffff;
  box-shadow: -20px 0 50px rgba(15, 23, 42, 0.14);
  overflow: auto;
}

.wordbook-head,
.wordbook-list-head,
.word-main-row,
.asset-head,
.field-title-row,
.item-card-top,
.detail-header,
.viewer-top,
.word-result-actions {
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.wordbook-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.word-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.word-result,
.word-result-empty,
.word-list,
.word-history-search {
  margin-top: 12px;
}

.word-result,
.word-result-empty {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.word-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100dvh - 380px);
  overflow: auto;
}

.word-chip,
.item-card {
  width: 100%;
  text-align: left;
}

.word-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.word-chip-main,
.item-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  background: #ffffff;
  cursor: pointer;
}

.word-chip-main {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
}

.word-chip-main > div {
  min-width: 0;
}

.item-card {
  padding: 12px;
}

.word-chip.active .word-chip-main,
.item-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.word-chip-term {
  display: block;
  font-size: 15px;
}

.word-chip-translation {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-meaning {
  display: grid;
  gap: 6px;
  line-height: 1.55;
}

.translation-block {
  margin-top: 10px;
}

.translation-block strong {
  display: block;
  margin-top: 4px;
}

.board {
  flex: 1;
  gap: 12px;
  min-height: 0;
}

.list-panel {
  width: 330px;
  display: flex;
  flex-direction: column;
}

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

.stat-chip {
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.stat-chip strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

.item-list {
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-kind,
.tag {
  padding: 4px 8px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
}

.item-time {
  flex-shrink: 0;
}

.item-title {
  margin: 7px 0 5px;
  line-height: 1.35;
  font-size: 15px;
}

.item-source,
.item-notes {
  line-height: 1.45;
}

.item-notes {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.item-tags,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.preview-panel {
  flex: 1;
  padding: 16px;
  min-height: 0;
}

.empty-state,
.detail-card {
  height: 100%;
}

.empty-state {
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.detail-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-header {
  align-items: flex-start;
}

.detail-header h3 {
  margin-top: 4px;
  font-size: 22px;
}

.detail-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.meta-card,
.notes-card,
.viewer-card {
  padding: 12px;
}

.meta-card {
  flex: 1 1 220px;
}

.meta-card strong {
  display: block;
  margin-top: 6px;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.45;
}

.notes-box {
  margin-top: 8px;
  white-space: pre-wrap;
  line-height: 1.55;
}

.viewer-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 360px;
}

.viewer {
  flex: 1;
  margin-top: 10px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #eef2f7;
  border: 1px solid var(--line);
}

.viewer iframe {
  width: 100%;
  height: calc(100% - 56px);
  border: 0;
}

.preview-fallback {
  height: 100%;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  line-height: 1.6;
}

.preview-actions-card {
  background: #ffffff;
}

.center-actions {
  justify-content: center;
  margin-top: 14px;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
  }

  .board {
    flex-direction: column;
  }

  .list-panel {
    width: 100%;
  }
}

@media (max-width: 860px) {
  body {
    padding: 10px;
  }

  .shell {
    min-height: calc(100vh - 20px);
  }

  .toolbar,
  .toolbar-actions,
  .upload-row,
  .stored-row,
  .detail-header,
  .detail-actions,
  .viewer-actions,
  .word-result-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-filters,
  .word-search-form,
  .stats-bar {
    grid-template-columns: 1fr;
  }

  .wordbook-panel {
    width: 100%;
  }
}
