:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687385;
  --line: #d9e0ea;
  --correct: #1f9f9a;
  --present: #e9782e;
  --absent: #eef1f5;
  --absent-text: #7c8797;
  --danger: #bd2f2f;
  --shadow: 0 18px 50px rgba(28, 39, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(31, 159, 154, 0.08), rgba(246, 248, 251, 0) 280px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 16px 40px;
}

.site-credit {
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.side-panel {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 6vw, 36px);
  line-height: 1.08;
  letter-spacing: 0;
}

.icon-button,
.primary-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 46px;
  flex: 0 0 46px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(28, 39, 58, 0.1);
  font-size: 24px;
}

.status-panel,
.guess-form,
.play-panel,
.achievement-panel,
.rules {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.status-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
  margin-bottom: 14px;
}

.status-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

#attemptStatus {
  font-size: 22px;
}

.message {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.message.error {
  color: var(--danger);
}

.play-panel {
  padding: 16px;
}

.achievement-panel {
  margin-top: 14px;
  padding: 14px;
}

.achievement-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.achievement-panel-head strong {
  min-width: 30px;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--present);
  color: white;
  text-align: center;
}

.achievement-list,
.result-achievement-list {
  display: grid;
  gap: 8px;
}

.achievement-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}

.achievement-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--present);
  font-size: 16px;
  line-height: 1.25;
}

.achievement-item p,
.empty-achievement {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.guess-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px;
  margin-bottom: 14px;
}

.guess-input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  font-size: 20px;
  outline: none;
}

.guess-input:focus {
  border-color: var(--correct);
  box-shadow: 0 0 0 4px rgba(31, 159, 154, 0.12);
}

.primary-button {
  padding: 0 18px;
  background: var(--correct);
  color: white;
  font-weight: 800;
}

.secondary-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.primary-button:disabled,
.secondary-button:disabled,
.guess-input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.board {
  display: grid;
  gap: 10px;
}

.board:empty::before {
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  content: "猜测记录会显示在这里";
}

.guess-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tile {
  min-width: 0;
  aspect-ratio: 0.92;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--absent);
  color: var(--absent-text);
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  padding: 4px 4px 7px;
}

.tile.correct {
  border-color: var(--correct);
  background: var(--correct);
  color: white;
}

.tile.present {
  border-color: var(--present);
  background: var(--present);
  color: white;
}

.part-line {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
  border-radius: 5px;
  padding: 1px 4px;
  color: var(--absent-text);
  background: rgba(255, 255, 255, 0.62);
  font-size: clamp(10px, 2.6vw, 13px);
  line-height: 1.25;
  white-space: nowrap;
}

.badge.correct {
  color: #fff;
  background: var(--correct);
}

.badge.present {
  color: #fff;
  background: var(--present);
}

.hanzi {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(26px, 7.5vw, 42px);
  line-height: 1;
}

.rules {
  margin-top: 0;
  padding: 0;
  box-shadow: none;
}

.rules summary {
  min-height: 48px;
  padding: 13px 16px;
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
}

.rule-content {
  border-top: 1px solid var(--line);
  padding: 14px 16px 16px;
  color: var(--muted);
  line-height: 1.65;
}

.rule-content p {
  margin: 0 0 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 14px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}

.swatch.correct {
  background: var(--correct);
}

.swatch.present {
  background: var(--present);
}

.swatch.absent {
  background: var(--absent);
  border: 1px solid var(--line);
}

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

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.44);
}

.dialog-backdrop[hidden] {
  display: none;
}

.result-dialog {
  position: relative;
  width: min(100%, 560px);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 32, 51, 0.24);
  padding: 24px;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--absent);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.achievement-block span {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.result-dialog h2 {
  margin: 0 44px 18px 0;
  font-size: clamp(28px, 6vw, 40px);
  line-height: 1.15;
  letter-spacing: 0;
}

.result-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.result-summary span {
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--absent);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.meaning-block,
.achievement-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fbfcfe;
}

.meaning-block p,
.achievement-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.meaning-block p {
  font-size: 18px;
  line-height: 1.75;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.dialog-actions .primary-button,
.dialog-actions .secondary-button {
  flex: 1 1 130px;
}

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

  .status-panel {
    grid-template-columns: 1fr;
  }

  .play-panel {
    padding: 12px;
  }

  .achievement-panel {
    padding: 12px;
  }

  .guess-form {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .primary-button {
    width: 100%;
  }

  .dialog-actions .primary-button,
  .dialog-actions .secondary-button {
    width: 100%;
  }

  .guess-row {
    gap: 6px;
  }

  .tile {
    padding-inline: 3px;
  }
}

@media (min-width: 900px), (orientation: landscape) and (min-width: 760px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    width: min(100%, 1380px);
    height: 100vh;
    min-height: 0;
    display: grid;
    grid-template-columns: clamp(280px, 28vw, 360px) minmax(0, 1fr) clamp(220px, 20vw, 280px);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 18px;
    padding: 18px;
  }

  .side-panel {
    position: sticky;
    top: 18px;
    align-self: start;
    max-height: calc(100vh - 72px);
    overflow: auto;
    padding-right: 2px;
  }

  .topbar {
    align-items: flex-start;
    margin-bottom: 14px;
  }

  h1 {
    font-size: clamp(26px, 3vw, 36px);
  }

  .status-panel {
    grid-template-columns: 1fr;
  }

  .guess-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .play-panel {
    min-height: 0;
    padding: 14px;
    overflow: hidden;
  }

  .achievement-panel {
    min-height: 0;
    max-height: calc(100vh - 72px);
    margin-top: 0;
    overflow: auto;
  }

  .board {
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    padding-right: 4px;
  }

  .site-credit {
    grid-column: 1 / -1;
    margin-top: -8px;
    text-align: center;
  }

  .guess-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tile {
    height: clamp(72px, 13vh, 112px);
    aspect-ratio: auto;
    padding: 2px 4px 6px;
  }

  .hanzi {
    font-size: clamp(30px, 4.2vw, 44px);
  }

  .badge {
    font-size: clamp(10px, 1.2vw, 12px);
  }
}
