:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #191613;
  --surface: #ffffff;
  --muted: #6f6761;
  --line: rgba(25, 22, 19, 0.1);
  --line-strong: rgba(25, 22, 19, 0.18);
  --cell: #ffffff;
  --cell-hover: color-mix(in oklab, var(--surface), var(--fg) 4%);
  --focus: #6d4b3e;
  --overlay: rgba(255, 255, 255, 0.94);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11100f;
    --fg: #f2ece5;
    --surface: #171513;
    --muted: #b9afa4;
    --line: rgba(242, 236, 229, 0.12);
    --line-strong: rgba(242, 236, 229, 0.22);
    --cell: #171513;
    --cell-hover: color-mix(in oklab, var(--surface), var(--fg) 8%);
    --focus: #ddb39c;
    --overlay: rgba(17, 16, 15, 0.95);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-serif, "Songti SC", STSong, "Noto Serif CJK SC", "Noto Serif CJK TC", serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.site-nav {
  align-items: center;
  background: color-mix(in oklab, var(--bg), transparent 6%);
  border-bottom: 1px solid var(--line);
  display: flex;
  font: 15px/1.4 "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  gap: 18px;
  justify-content: space-between;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  z-index: 4;
}

.brand,
.site-nav a {
  color: inherit;
  text-decoration: none;
}

.brand {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: 18px;
  font-weight: 600;
}

.site-nav nav {
  display: flex;
  gap: 16px;
}

.site-nav nav a {
  color: var(--muted);
}

.site-nav nav a:hover,
.site-nav nav a[aria-current="page"] {
  color: var(--focus);
}

.close {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.close:hover {
  background: var(--cell-hover);
}

.matrix {
  display: grid;
  gap: 1px;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  padding: 1px;
}

.cell {
  align-items: center;
  aspect-ratio: 1;
  background: var(--cell);
  border: 0;
  color: var(--fg);
  cursor: pointer;
  display: flex;
  font-family: inherit;
  font-size: clamp(20px, 4.8vw, 28px);
  justify-content: center;
  line-height: 1;
  min-width: 0;
  padding: 0;
}

.cell:hover {
  background: var(--cell-hover);
}

.cell.selected {
  box-shadow: inset 0 0 0 2px var(--focus);
  position: relative;
  z-index: 1;
}

.detail {
  align-items: center;
  background: var(--overlay);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 16px;
  position: fixed;
  z-index: 10;
}

.detail[hidden] {
  display: none;
}

.close {
  font-size: 22px;
  position: fixed;
  right: 14px;
  top: 58px;
}

.detail-card {
  display: grid;
  gap: 18px;
  justify-items: center;
  max-width: min(720px, 100%);
  width: 100%;
}

.pinyin {
  color: var(--muted);
  font: 22px/1.2 ui-sans-serif, system-ui, sans-serif;
  min-height: 28px;
  text-align: center;
}

.middle {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: 40px minmax(0, 1fr);
  justify-items: center;
  width: min(460px, 100%);
}

.zhuyin {
  color: var(--muted);
  font-size: 26px;
  line-height: 1.15;
  min-height: 160px;
  writing-mode: vertical-rl;
}

.big-char {
  font-size: clamp(150px, 42vw, 340px);
  line-height: 0.95;
  min-width: 0;
  text-align: center;
}

.english {
  color: var(--fg);
  font: 20px/1.45 ui-sans-serif, system-ui, sans-serif;
  max-width: 52ch;
  min-height: 30px;
  text-align: center;
}

@media (min-width: 720px) {
  .matrix {
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  }

  .cell {
    font-size: 30px;
  }
}

@media (max-width: 420px) {
  .matrix {
    grid-template-columns: repeat(auto-fill, minmax(31px, 1fr));
  }
}
