@font-face {
  font-family: "Sudoku Serif";
  src: url("fonts/serif.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  --paper: #f7efe6;
  --white: #fffcf6;
  --ink: #3c2823;
  --muted: #765d52;
  --line: #e9d9cc;
  --wine: #8a3733;
  --wine-dark: #72312b;
  --blush: #faeae3;
  --green: #396451;
  --red: #b04745;
  --serif: "Sudoku Serif", "Songti SC", "Noto Serif CJK SC", SimSun, serif;
  --sans: "DM Sans", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0, #fdf6ee, transparent 600px), var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
}
button {
  min-height: 44px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: default; }
button:focus { outline: 2px solid var(--wine-dark); outline-offset: 2px; }
button:focus-visible { outline: 2px solid var(--wine-dark); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }
h1, h2, p { margin: 0; }

.shell { max-width: 448px; margin: 0 auto; padding: 18px 18px 12px; }
.masthead {
  display: flex;
  align-items: center;
  min-height: 49px;
  margin: 0 0 12px;
}
.masthead h1 {
  margin: 0 0 2px 11px;
  color: var(--wine-dark);
  font: 600 31px/1.18 var(--serif);
  letter-spacing: .065em;
}
.brand-mark {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, 7px);
  grid-template-rows: repeat(2, 7px);
  grid-gap: 3px;
  align-content: center;
  justify-content: center;
  width: 39px;
  height: 39px;
  border-radius: 10px;
  background: var(--wine);
  box-shadow: inset 0 0 0 1px rgba(59, 18, 14, .1), 0 2px 3px rgba(108, 44, 30, .16);
  transform: rotate(-5deg);
}
.brand-mark i { border: 1px solid #fff2da; border-radius: 1px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: #fff2da; }
.date {
  margin-left: auto;
  padding-left: 8px;
  color: var(--muted);
  font: 600 13px/1.25 Georgia, serif;
  letter-spacing: .055em;
  white-space: nowrap;
}

.modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-gap: 5px;
  padding: 4px;
  border: 1px solid #e7d6c9;
  border-radius: 13px;
  background: #f0e4da;
}
.mode {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 6px;
  border: 0;
  border-radius: 8px;
  color: #6a5047;
  background: transparent;
  font-weight: 700;
}
.mode[aria-pressed="true"] {
  background: var(--wine);
  color: #fff9f0;
  box-shadow: 0 2px 3px rgba(108, 44, 30, .18);
}
.mode-icon {
  position: relative;
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 1px solid currentColor;
  border-radius: 3px;
}
.mode-icon::before, .mode-icon::after { position: absolute; display: block; content: ""; }
.calendar::before { top: 3px; left: 0; right: 0; border-top: 1px solid currentColor; }
.calendar::after { width: 3px; height: 3px; bottom: 2px; left: 4px; background: currentColor; }
.practice-icon::before { left: 5px; top: 1px; bottom: 1px; border-left: 1px solid currentColor; }
.practice-icon::after { top: 5px; left: 1px; right: 1px; border-top: 1px solid currentColor; }
.difficulties {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-gap: 7px;
  margin-top: 9px;
}
.difficulties button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--muted);
  font-weight: 600;
}
.difficulties [aria-pressed="true"] { border-color: #c88a7b; color: var(--wine-dark); background: var(--blush); }

.paper {
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--white);
  box-shadow: 0 4px 14px rgba(91, 42, 22, .045);
}
.board-panel { margin-top: 12px; padding: 14px 15px 11px; }
.tray-panel { margin-top: 10px; padding: 9px 15px 11px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; }
.panel-heading h2 {
  padding-left: 8px;
  border-left: 2px solid #bf7462;
  color: var(--ink);
  font: 600 19px/1.22 var(--serif);
  letter-spacing: .06em;
}
.filled { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.instructions { margin-top: 5px; color: var(--muted); font-size: 12px; }

.board-square { position: relative; margin: 10px auto 0; max-width: 340px; }
.board-square::before { display: block; padding-top: 100%; content: ""; }
.board {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  grid-gap: 6px;
  padding: 10px;
  border: 1px solid #e8dcd0;
  border-radius: 13px;
  background: #f6eee4;
}
.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0 0 2px;
  border: 1px solid #e0cbb9;
  border-radius: 8px;
  box-shadow: 0 2px 0 #efe0d2;
  background: #fffaf1;
  font: 600 29px/1 var(--serif);
}
.cell.row-0 { grid-row: 1; }
.cell.row-1 { grid-row: 2; }
.cell.row-2 { grid-row: 3; }
.cell.row-3 { grid-row: 4; }
.cell.col-0 { grid-column: 1; }
.cell.col-1 { grid-column: 2; }
.cell.col-2 { grid-column: 3; }
.cell.col-3 { grid-column: 4; }
.cell:disabled { opacity: 1; }
.cell[data-given="true"] {
  border-color: #dfc7b2;
  box-shadow: 0 2px 0 #ebd7c6;
  background: #ead7c3;
  color: #573f32;
}
.cell[data-given="true"]::after {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 4px;
  height: 4px;
  border-radius: 1px;
  background: #986d58;
  content: "";
}
.cell[aria-pressed="true"] {
  border-color: #a95449;
  box-shadow: inset 0 0 0 1px #a95449, 0 2px 0 #edcfc4;
  background: #fbe9e1;
  color: var(--wine-dark);
}
.cell-letter:empty::before {
  display: block;
  width: 8px;
  height: 2px;
  border-radius: 2px;
  background: #cdb4a0;
  content: "";
}
.cell[aria-pressed="true"] .cell-letter:empty::before { background: #a45548; }

.center {
  grid-area: 2 / 2 / 4 / 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid #e9d9cb;
  border-radius: 9px;
  background: radial-gradient(ellipse, #f9f0e5, #f3e7d9);
  color: var(--wine-dark);
}
.center-title { font: 600 21px/1.3 var(--serif); letter-spacing: .07em; white-space: nowrap; }
.center-meta { display: flex; align-items: center; margin-top: 6px; color: #785746; font-size: 12px; }
.center-meta time { font: 700 14px/1.1 Georgia, serif; letter-spacing: .045em; font-variant-numeric: tabular-nums; }
.divider { width: 3px; height: 3px; margin: 0 8px; border-radius: 50%; background: #bd8b75; }
.center-rule { display: block; width: 27px; height: 1px; margin: 0 0 9px; background: #d6b49f; }
.center-rule:last-child { margin: 10px 0 0; }

.rail {
  position: absolute;
  pointer-events: none;
  border: 0 solid transparent;
  border-radius: 2px;
}
.rail-top, .rail-bottom { right: 18px; left: 18px; border-top-width: 3px; }
.rail-left, .rail-right { top: 18px; bottom: 18px; border-left-width: 3px; }
.rail-top { top: 3px; }
.rail-right { right: 3px; }
.rail-bottom { bottom: 3px; }
.rail-left { left: 3px; }
.rail[data-state="valid"] { border-color: var(--green); }
.rail[data-state="invalid"] { border-color: var(--red); border-style: dashed; }

.legend { display: flex; justify-content: center; flex-wrap: wrap; margin-top: 8px; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; margin: 0 8px; white-space: nowrap; }
.sample { display: inline-block; width: 12px; margin-right: 5px; }
.given-sample { height: 10px; border: 1px solid #bd9379; border-radius: 2px; background: #ead7c3; }
.valid-sample { border-top: 2px solid var(--green); }
.invalid-sample { border-top: 2px dashed var(--red); }

.tray-panel .instructions { margin-top: 0; }
.tray {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-gap: 6px;
  margin-top: 9px;
}
.key {
  min-width: 0;
  padding: 0 0 2px;
  border: 1px solid #e6d5c4;
  border-radius: 7px;
  box-shadow: 0 2px 0 #eddfd1;
  background: #faf1e6;
  font: 600 22px/1 var(--serif);
}
.key:active { transform: translateY(1px); box-shadow: 0 1px 0 #e4c7b8; background: #f8e5da; }
.key:disabled { opacity: .72; }
.clear {
  min-height: 34px;
  min-width: 61px;
  padding: 2px 10px;
  border: 1px solid #dfc5b7;
  border-radius: 7px;
  background: #fff8f1;
  color: var(--wine-dark);
  font-size: 12px;
  font-weight: 650;
}
.clear:disabled { border-color: var(--line); background: #f9f1e9; color: #765d52; }
.record { display: flex; justify-content: space-between; margin: 11px 3px 0; color: var(--muted); font-size: 12px; }
.record .done { color: var(--green); }

.result {
  position: fixed;
  width: calc(100% - 32px);
  max-width: 392px;
  max-height: calc(100% - 32px);
  padding: 23px 18px 17px;
  color: var(--ink);
  text-align: center;
  overflow: auto;
}
.result:not([open]) { display: none; }
.result[open] { display: block; overscroll-behavior: contain; }
.result.fallback { position: relative; max-height: none; margin: 16px auto; }
.result::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(60, 40, 35, .48);
}
.close {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
}
.close::before, .close::after {
  position: absolute;
  top: 21px;
  left: 14px;
  width: 16px;
  border-top: 1px solid currentColor;
  content: "";
  transform: rotate(45deg);
}
.close::after { transform: rotate(-45deg); }
.win-mark {
  display: block;
  width: 36px;
  height: 36px;
  margin: 0 auto 9px;
  border: 1px solid #c6d4c3;
  border-radius: 50%;
  background: #ebf0e4;
}
.win-mark::before {
  display: block;
  width: 13px;
  height: 7px;
  margin: 10px auto;
  border: solid var(--green);
  border-width: 0 0 2px 2px;
  content: "";
  transform: rotate(-45deg);
}
.result-title {
  color: var(--wine-dark);
  font: 600 29px/1.3 var(--serif);
  letter-spacing: .10em;
}
.result-meta { margin: 5px 0 14px; color: var(--muted); font-size: 13px; }
.result-words {
  margin: 0 0 14px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #faf3eb;
  list-style: none;
  text-align: left;
}
.result-words li {
  display: grid;
  grid-template-columns: 24px minmax(70px, .8fr) minmax(0, 1fr);
  grid-gap: 6px;
  align-items: center;
  min-height: 43px;
  padding: 5px 0;
}
.result-words li + li { border-top: 1px solid var(--line); }
.side-tag { color: var(--green); font-size: 11px; }
.result-word { font: 600 17px/1.2 var(--serif); white-space: nowrap; }
.pinyin { text-align: right; color: var(--muted); font-size: 12px; }
.primary, .secondary {
  width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--wine);
  border-radius: 9px;
  background: var(--wine);
  color: #fff9f1;
  font-weight: 700;
}
.secondary { border-color: #debcac; background: #fff8f1; color: var(--wine-dark); }
#next { margin-top: 8px; }
.poster-title { margin-bottom: 12px; color: var(--wine-dark); font: 600 23px/1.3 var(--serif); }
#poster {
  display: block;
  width: 100%;
  max-width: 290px;
  height: auto;
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.poster-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-gap: 8px; margin-top: 12px; }
.back { margin-top: 5px; padding: 4px 13px; border: 0; background: transparent; color: var(--wine-dark); }
.toast {
  position: fixed;
  right: 0;
  bottom: 18px;
  left: 0;
  z-index: 2;
  margin: 0 auto;
  width: calc(100% - 48px);
  max-width: 350px;
  border-radius: 8px;
  background: #53372d;
  color: #fff9f0;
  text-align: center;
  font-size: 13px;
  pointer-events: none;
}
.toast:not(:empty) { padding: 8px 12px; }
.dialog-toast { position: sticky; bottom: 0; width: 100%; }
.dialog-toast:not(:empty) { margin-top: 5px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
@media (max-width: 365px) {
  .shell { padding-left: 14px; padding-right: 14px; }
  .board-panel, .tray-panel { padding-left: 12px; padding-right: 12px; }
  .masthead h1 { font-size: 28px; }
}
@media (pointer: coarse) {
  .clear { min-height: 44px; }
}

.cell.invalid-top { border-top-color: var(--red); }
.cell.invalid-right { border-right-color: var(--red); }
.cell.invalid-bottom { border-bottom-color: var(--red); }
.cell.invalid-left { border-left-color: var(--red); }
