:root {
  --ink: #30463f;
  --muted: #6d7f78;
  --paper: #f7f4ec;
  --card: #fffdf7;
  --sage: #56766a;
  --sage-dark: #3e5f54;
  --sage-pale: #e4eee8;
  --cream: #f3e6c8;
  --rose: #c97373;
  --line: #d9dfd8;
  color-scheme: light;
  font-family:
    ui-rounded, "SF Pro Rounded", "PingFang TC", "Microsoft JhengHei",
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 5% 0%, rgba(190, 216, 202, 0.45), transparent 24rem),
    var(--paper);
}

button,
select,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 20px 16px 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 16px;
}

.mode-label,
.modal-kicker {
  margin: 0;
  color: var(--sage);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.17em;
}

h1 {
  margin: 2px 0 0;
  font-family: Georgia, "Noto Serif TC", serif;
  font-size: clamp(2rem, 9vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.06em;
}

.top-actions {
  display: flex;
  gap: 7px;
}

.icon-button {
  min-width: 48px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #cdd8d1;
  border-radius: 999px;
  color: var(--sage-dark);
  background: rgba(255, 253, 247, 0.86);
  font-size: 0.73rem;
  font-weight: 800;
  cursor: pointer;
}

.status-card {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 0.7fr auto;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border: 1px solid rgba(62, 95, 84, 0.13);
  border-radius: 17px;
  background: rgba(255, 253, 247, 0.82);
}

.level-picker,
.difficulty {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.level-picker > span,
.difficulty > span {
  color: var(--muted);
  font-size: 0.63rem;
  font-weight: 800;
}

#level-select {
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 850;
}

.difficulty strong {
  font-size: 0.85rem;
}

.hearts {
  min-width: 72px;
  color: var(--rose);
  font-size: 1.14rem;
  letter-spacing: 0.08em;
  text-align: right;
}

.hearts .is-empty {
  color: #d9d8d2;
}

.game-panel {
  margin-top: 12px;
  padding: 18px;
  border: 1px solid rgba(62, 95, 84, 0.13);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 14px 34px rgba(62, 95, 84, 0.07);
}

.board-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.board-heading > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#board-size {
  color: var(--sage);
  font-size: 0.67rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.board-heading strong {
  font-size: 0.9rem;
}

.board-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.67rem;
  text-align: right;
}

.board {
  display: grid;
  width: min(100%, 520px);
  aspect-ratio: 1;
  margin: 0 auto;
  grid-template-columns: repeat(var(--size), 1fr);
  overflow: hidden;
  border: 2px solid var(--sage-dark);
  border-radius: 14px;
  background: var(--sage-dark);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  border-style: solid;
  border-color: rgba(62, 95, 84, 0.28);
  color: var(--ink);
  background: var(--region-color);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: filter 120ms ease, transform 120ms ease;
}

.cell:hover {
  filter: brightness(1.035);
}

.cell:active,
.cell.is-pressing {
  filter: brightness(0.95);
  transform: scale(0.96);
}

.cell:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  position: relative;
  z-index: 2;
  outline: 3px solid #e8a75b;
  outline-offset: 2px;
}

.cell-mark {
  display: grid;
  width: 78%;
  height: 78%;
  place-items: center;
  border-radius: 50%;
  line-height: 1;
  pointer-events: none;
}

.cell[data-state="cross"] .cell-mark {
  color: rgba(48, 70, 63, 0.63);
  font-size: clamp(1rem, calc(4.8rem / var(--size)), 2rem);
  font-weight: 500;
}

.cell[data-state="cow"] .cell-mark,
.cell.is-solution .cell-mark {
  border: 2px solid rgba(62, 95, 84, 0.24);
  background: rgba(255, 253, 247, 0.88);
  box-shadow: 0 3px 8px rgba(62, 95, 84, 0.12);
  font-size: clamp(0.95rem, calc(5rem / var(--size)), 2.1rem);
}

.cell.is-solution:not([data-state="cow"]) .cell-mark::after {
  content: "🐮";
}

.cell.is-hint {
  z-index: 1;
  animation: hint-glow 900ms ease 2;
}

.board.is-locked .cell {
  cursor: default;
}

.game-message {
  min-height: 1.4em;
  margin: 13px 2px 0;
  color: var(--sage-dark);
  font-size: 0.78rem;
  font-weight: 750;
  text-align: center;
}

.game-message.is-error {
  color: #a65353;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.toolbar button {
  display: flex;
  min-width: 0;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 7px 4px;
  border: 1px solid #d1dbd5;
  border-radius: 15px;
  color: var(--sage-dark);
  background: rgba(255, 253, 247, 0.86);
  font-size: 0.7rem;
  font-weight: 850;
  cursor: pointer;
}

.toolbar button span:first-child {
  font-size: 1.05rem;
}

.toolbar button:hover,
.icon-button:hover {
  background: var(--sage-pale);
}

.toolbar button:active,
.icon-button:active {
  transform: translateY(1px);
}

.toolbar button:disabled {
  color: #9ba7a2;
  background: #efefea;
  cursor: not-allowed;
}

.footer-note {
  margin: 16px 8px 0;
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.55;
  text-align: center;
}

.modal {
  width: min(calc(100% - 28px), 510px);
  max-height: min(82vh, 680px);
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 24px 80px rgba(48, 70, 63, 0.28);
}

.modal::backdrop {
  background: rgba(39, 55, 50, 0.44);
  backdrop-filter: blur(3px);
}

.modal article {
  position: relative;
  padding: 28px 25px;
}

.modal--small {
  max-width: 420px;
}

.modal h2 {
  margin: 6px 0 18px;
  font-family: Georgia, "Noto Serif TC", serif;
  font-size: 1.8rem;
}

.modal h3 {
  margin: 20px 0 6px;
  font-size: 0.93rem;
}

.modal p,
.modal li {
  color: #53665f;
  font-size: 0.84rem;
  line-height: 1.7;
}

.modal ol {
  padding-left: 1.25rem;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: #edf1ed;
  font-size: 1.25rem;
  cursor: pointer;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 0 4px;
  font-weight: 800;
}

.setting-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--sage);
}

.setting-note {
  margin-bottom: 0;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 22px;
}

.dialog-actions:has(#review-answer:not([hidden])) {
  grid-template-columns: 1fr 1fr;
}

.dialog-actions button {
  min-height: 48px;
  padding: 9px 12px;
  border: 1px solid #ccd8d1;
  border-radius: 13px;
  color: var(--sage-dark);
  background: #f4f4ee;
  font-weight: 850;
  cursor: pointer;
}

.dialog-actions .primary-action {
  border-color: var(--sage);
  color: #fff;
  background: var(--sage);
}

.modal--result {
  text-align: center;
}

.result-cow {
  margin: 0;
  font-size: 3.5rem !important;
  line-height: 1 !important;
}

.result-stars {
  margin: 0;
  color: #d5a23e !important;
  font-size: 1.65rem !important;
  letter-spacing: 0.12em;
}

@keyframes hint-glow {
  50% {
    filter: brightness(1.12);
    box-shadow: inset 0 0 0 4px #f0b451;
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 11px;
  }

  .status-card {
    gap: 8px;
    padding-inline: 11px;
  }

  .hearts {
    min-width: 62px;
    font-size: 1rem;
  }

  .game-panel {
    padding: 14px;
    border-radius: 18px;
  }

  .board-heading p {
    max-width: 9rem;
  }
}

@media (min-width: 620px) {
  .app-shell {
    padding-top: 34px;
  }

  .game-panel {
    padding: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
