:root {
  --paper: #f2eee6;
  --surface: #fffdf9;
  --ink: #27231f;
  --muted: #776e63;
  --line: #ddd5c8;
  --line-soft: #eee8df;
  --accent: #a74637;
  --accent-soft: #f5e4df;
  --mask: #dedbd3;
  --toolbar-height: 0px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

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

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.toolbar {
  position: sticky;
  z-index: 30;
  top: 0;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.97);
  box-shadow: 0 2px 14px rgba(46, 38, 28, 0.07);
  backdrop-filter: blur(14px);
}

.toolbar-inner {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 12px 18px 10px;
}

.title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 9px;
}

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

h1 {
  margin-bottom: 1px;
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  font-size: 23px;
  letter-spacing: 0.03em;
}

.title-row p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.controls,
.button-row,
.sync-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.primary-control,
.secondary-button,
.icon-button,
.check-control,
.select-control {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.primary-control,
.secondary-button,
.icon-button {
  padding: 6px 13px;
  font-weight: 680;
}

.primary-control:hover,
.secondary-button:hover,
.icon-button:hover,
.check-control:hover,
.select-control:hover {
  border-color: #bdb2a4;
  background: #faf7f1;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

.check-control,
.select-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
}

.check-control {
  cursor: pointer;
}

.check-control input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--accent);
}

.select-control {
  color: var(--muted);
}

.select-control select {
  max-width: 165px;
  border: 0;
  background: transparent;
  font-weight: 650;
}

.count {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.settings-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}

.settings-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #faf7f1;
}

.settings-block h2 {
  margin-bottom: 3px;
  font-size: 14px;
}

.settings-block p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

code {
  color: #68574b;
  font-size: 0.92em;
}

.sync-form input {
  flex: 1 1 260px;
  min-width: 160px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 9px;
  background: #fff;
  font-size: 16px;
}

.text-button {
  min-height: 36px;
  border: 0;
  padding: 5px 7px;
  color: var(--muted);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sync-status {
  margin: 7px 0 0 !important;
}

.save-status {
  margin: 7px 0 0 !important;
}

main {
  width: min(1220px, calc(100% - 28px));
  margin: 18px auto 40px;
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 9px 30px rgba(57, 46, 31, 0.07);
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.mark-col {
  width: 48px;
}

.word-col {
  width: 22%;
}

.meaning-col {
  width: auto;
}

.note-col {
  width: 29%;
}

thead th {
  position: sticky;
  z-index: 15;
  top: var(--toolbar-height);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
  background: #f7f3ec;
  font-size: 12px;
  font-weight: 680;
  letter-spacing: 0.06em;
  text-align: left;
}

thead th:first-child {
  text-align: center;
}

tbody td {
  border-bottom: 1px solid var(--line-soft);
  padding: 6px 10px;
  vertical-align: middle;
  background: var(--surface);
}

.group-row td {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  color: #61574d;
  background: #eee8de;
  font-size: 13px;
  font-weight: 760;
}

.group-row:first-child td {
  border-top: 0;
}

.mark-cell {
  padding: 0;
  text-align: center;
}

.mark-button {
  display: grid;
  width: 100%;
  min-height: 42px;
  place-items: center;
  border: 0;
  padding: 0;
  color: var(--accent);
  background: transparent;
  font-size: 20px;
  line-height: 1;
}

.mark-button:not(.is-marked):hover::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1px solid #c5b9aa;
  border-radius: 50%;
}

.word-cell {
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-weight: 700;
}

.meaning-cell {
  position: relative;
  min-height: 40px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.meaning-cell:hover {
  background: #faf7f1;
}

.meaning-cell.is-hidden .meaning-text {
  color: transparent;
  user-select: none;
}

.meaning-cell.is-hidden::after {
  content: "";
  position: absolute;
  inset: 7px 9px;
  border: 1px solid #d1cdc4;
  border-radius: 4px;
  background:
    repeating-linear-gradient(
      -35deg,
      rgba(255, 255, 255, 0.18) 0,
      rgba(255, 255, 255, 0.18) 4px,
      transparent 4px,
      transparent 8px
    ),
    var(--mask);
}

.note-cell {
  padding: 5px 8px;
}

.note-input {
  width: 100%;
  min-width: 0;
  height: 33px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 4px 7px;
  background: transparent;
  font-size: 16px;
}

.note-input:hover,
.note-input:focus {
  border-color: var(--line);
  background: #fff;
}

.note-input::placeholder {
  color: #b2a99e;
}

.empty-row td {
  padding: 48px 20px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 60;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
  max-width: min(360px, calc(100% - 32px));
  border: 1px solid #cdbfaf;
  border-radius: 8px;
  padding: 9px 12px;
  color: #4c4037;
  background: #fffaf2;
  box-shadow: 0 6px 24px rgba(45, 36, 27, 0.15);
  font-size: 13px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.meaning-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  :root {
    --toolbar-height: 0px;
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
    font-size: 14px;
  }

  .toolbar {
    position: static;
  }

  .toolbar-inner {
    padding: 9px 8px 8px;
  }

  .title-row {
    align-items: center;
    margin-bottom: 7px;
  }

  h1 {
    font-size: 19px;
  }

  .desktop-label,
  .title-row p {
    display: none;
  }

  .icon-button {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    padding: 4px;
    font-size: 19px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .primary-control,
  .check-control,
  .select-control {
    width: 100%;
    min-height: 42px;
    justify-content: center;
    padding: 4px 6px;
  }

  .select-control select {
    max-width: 110px;
    font-size: 14px;
  }

  .count {
    grid-column: 1 / -1;
    margin-left: 0;
    padding: 1px 2px 0;
    text-align: center;
  }

  .settings-panel {
    grid-template-columns: 1fr;
    max-height: 62vh;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .settings-block {
    padding: 9px;
  }

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

  .sync-form input {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
  }

  .text-button {
    min-height: 42px;
  }

  main {
    width: 100%;
    margin: 8px 0 24px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .mark-col {
    width: 38px;
  }

  .word-col {
    width: 22%;
  }

  .meaning-col {
    width: 42%;
  }

  .note-col {
    width: auto;
  }

  thead th,
  tbody td {
    padding-right: 5px;
    padding-left: 5px;
  }

  thead th {
    top: 0;
    padding-top: 7px;
    padding-bottom: 7px;
    font-size: 11px;
    letter-spacing: 0;
  }

  .group-row td {
    padding: 7px 8px;
  }

  .mark-button {
    min-height: 44px;
  }

  .word-cell {
    font-size: 15px;
  }

  .meaning-cell {
    min-height: 44px;
    font-size: 13px;
  }

  .meaning-cell.is-hidden::after {
    inset: 7px 4px;
  }

  .note-cell {
    padding: 4px 3px;
  }

  .note-input {
    height: 36px;
    padding: 3px 4px;
  }
}

@media (max-width: 390px) {
  .word-col {
    width: 21%;
  }

  .meaning-col {
    width: 43%;
  }

  .word-cell {
    font-size: 14px;
  }

  .meaning-cell {
    font-size: 12.5px;
  }
}
