:root {
  --bg: #f3f1ec;
  --paper: #fbfaf7;
  --ink: #1a1a1a;
  --muted: #6f6a62;
  --line: #e2ddd4;
  --soft: #efece6;
  --danger: #8f3d32;
  color-scheme: light;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --paper: #1c1c1c;
    --ink: #f3f1ea;
    --muted: #a39e94;
    --line: #34312c;
    --soft: #262421;
    --danger: #e2a197;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 8px 14px;
  cursor: pointer;
}

button:hover { background: var(--soft); }

button.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

button.primary:hover { background: var(--ink); }

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px 16px;
  align-items: end;
  padding: 28px 32px 8px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 28px;
  font-weight: 560;
  letter-spacing: 0.04em;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.brand p, .keyhint, .record-note, .foot, .gloss, .reading-line, .field-label {
  color: var(--muted);
}

.brand p { margin-top: 6px; font-size: 14px; }

.keyhint { font-size: 13px; text-align: right; }

.tabs { display: none; grid-column: 1 / -1; }

.layout {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 32px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  align-items: start;
}

main, aside {
  min-width: 0;
}

.status {
  min-height: 1.4em;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.status.error { color: var(--danger); }

.record-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.record {
  min-width: 112px;
  min-height: 44px;
  padding: 10px 18px;
}

.record[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.field-label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.12em;
  margin-bottom: 6px;
}

textarea, input[type="search"] {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 12px 14px;
}

textarea {
  resize: vertical;
  min-height: 96px;
  font-family: "Yu Gothic UI", "Yu Gothic", "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 22px;
  line-height: 1.55;
}

textarea:focus, input:focus, button:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.result { margin-top: 28px; }

.translation {
  font-size: 20px;
  line-height: 1.5;
}

.gloss, .reading-line {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
}

.reading-line {
  font-family: "Yu Gothic UI", "Yu Gothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

.words {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.word, .vocab-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 14px;
}

.word .surface, .vocab-item .surface {
  font-family: "Yu Gothic UI", "Yu Gothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 26px;
  line-height: 1.35;
}

ruby rt {
  font-size: 0.42em;
  color: var(--muted);
}

.pos {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.senses {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  line-height: 1.55;
}

.word-actions, .vocab-actions, .aside-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.word-actions button, .vocab-actions button, .aside-actions button {
  padding: 4px 8px;
  font-size: 13px;
}

aside {
  position: sticky;
  top: 16px;
  border-left: 1px solid var(--line);
  padding-left: 20px;
}

.aside-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

#vocab-count { color: var(--muted); font-size: 13px; }

#vocab-search { margin-bottom: 12px; }

.vocab-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 240px);
  overflow: auto;
}

.vocab-item .surface { font-size: 20px; }

.vocab-meta, .empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.vocab-item[hidden] { display: none; }

.foot {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 32px 24px;
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.foot a { color: inherit; }

#awake-video {
  position: fixed;
  width: 1px;
  height: 1px;
  left: 0;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
}

.table-wrap { max-width: 100%; overflow-x: auto; }
.table-wrap .meter { min-width: 680px; }

.meter {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--paper);
}

.meter th, .meter td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.meter th {
  color: var(--muted);
  font-weight: 500;
}

.usage-page {
  max-width: 960px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 28px 32px 40px;
}

.usage-page h1 { margin-bottom: 8px; }
.usage-page h2 { margin: 22px 0 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.stats div {
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 12px 14px;
}

.stats strong {
  display: block;
  font-size: 22px;
  font-weight: 560;
  margin-top: 4px;
}

dialog {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 22px 22px 16px;
  max-width: 440px;
  width: calc(100% - 32px);
}

dialog h2 { margin-bottom: 12px; }

dialog dl { margin: 0; }

  dialog dl div {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 8px;
    padding: 7px 0;
    border-top: 1px solid var(--line);
    font-size: 14px;
  }

dialog dt { color: var(--muted); }

dialog form { margin-top: 14px; text-align: right; }

dialog::backdrop { background: rgba(0, 0, 0, 0.28); }

@media (max-width: 800px) {
  .top, .layout, .foot { padding-left: 16px; padding-right: 16px; }
  .top { padding-top: 18px; grid-template-columns: 1fr auto; }
  .keyhint { display: none; }
  h1 { font-size: 24px; }

  .tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .tabs button { min-height: 40px; }
  .tabs button[aria-selected="true"] {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
  }

  .layout { grid-template-columns: 1fr; gap: 0; }
  aside {
    position: static;
    border-left: 0;
    padding-left: 0;
    padding-top: 8px;
  }

  .layout[data-pane="study"] aside { display: none; }
  .layout[data-pane="vocab"] main { display: none; }

  .record-row {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 4;
    margin: 0;
    padding: 10px;
    background: var(--paper);
    border: 1px solid var(--line);
  }

  .record { flex: 1; }
  .record-note { display: none; }
  main { padding-bottom: 84px; }

  textarea { font-size: 20px; }
  .vocab-list { max-height: none; }

  dialog dl div { grid-template-columns: 1fr; gap: 2px; }
}

@media (max-width: 800px) {
  .stats { grid-template-columns: 1fr; }
  .usage-page { padding: 18px 16px 32px; }
}
