/* ============================================================
   数独 · game.54hrm.com
   ============================================================ */
:root {
  --paper: #faf9f6;
  --paper-2: #f3f1eb;
  --card: #ffffff;
  --ink: #1c2624;
  --ink-soft: #5b6b66;
  --ink-faint: #93a09b;
  --line: #ded9cd;
  --line-strong: #cfc9bc;
  --teal: #0e6b63;
  --teal-2: #14867b;
  --teal-soft: #e6f0ee;
  --teal-mist: #f2f7f6;
  --amber: #c98a3d;
  --amber-soft: #fbf1e2;
  --err: #c0483c;
  --err-soft: #fbeceb;
  --serif: "Iowan Old Style", "Songti SC", "Noto Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(28, 38, 36, .05);
  --shadow: 0 1px 2px rgba(28, 38, 36, .04), 0 12px 32px -16px rgba(28, 38, 36, .22);
  --shadow-lift: 0 2px 4px rgba(28, 38, 36, .05), 0 22px 48px -20px rgba(28, 38, 36, .3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background-image:
    radial-gradient(1000px 500px at 12% -8%, rgba(14, 107, 99, .055), transparent 60%),
    radial-gradient(800px 400px at 96% 4%, rgba(201, 138, 61, .05), transparent 62%);
  background-repeat: no-repeat;
}

::selection { background: var(--teal-soft); color: var(--teal); }

button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; border-radius: 8px; }

/* ---------------- layout ---------------- */
.app { max-width: 1080px; margin: 0 auto; padding: 0 20px 56px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 68px; gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 9px; text-decoration: none; color: var(--ink); }
.brand .logo { font-family: var(--serif); font-size: 21px; font-weight: 600; letter-spacing: .02em; }
.brand .logo em { font-style: normal; color: var(--teal); }
.brand .sub { font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint); }
.top-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  color: var(--ink-soft); border: 1px solid transparent; transition: all .18s;
  position: relative;
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn[aria-pressed="false"] { color: var(--ink-faint); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.on { background: var(--teal-soft); color: var(--teal); border-color: rgba(14, 107, 99, .18); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 26px;
  align-items: start;
  margin-top: 8px;
}

/* ---------------- board ---------------- */
.board-panel { min-width: 0; }

.board-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.board-title { font-size: 14.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; }
.board-title .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line-strong); }
.board-title b { color: var(--ink); font-weight: 600; }
.board-title .rank {
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px; letter-spacing: .04em;
  background: var(--teal-soft); color: var(--teal); font-weight: 600;
}
.board-title .rank.expert { background: #f6ecef; color: #9b3f57; }
.board-title .rank.hard { background: var(--amber-soft); color: #9a6524; }

.clock { display: flex; align-items: center; gap: 10px; }
.clock-time {
  font-family: var(--mono); font-size: 17px; font-variant-numeric: tabular-nums;
  color: var(--ink); letter-spacing: .02em; min-width: 62px; text-align: right;
}
.clock-time.paused { color: var(--ink-faint); }

.board-wrap { position: relative; }

.board {
  --gap: 0px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border: 2px solid #26332f;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(28, 38, 36, .06), 0 18px 40px -22px rgba(28, 38, 36, .3);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid #ddd7c9;
  border-bottom: 1px solid #ddd7c9;
  border-radius: 0;
  background: var(--card);
  transition: background-color .14s;
  min-width: 0; min-height: 0;
  font-size: clamp(19px, 3.6vw, 30px);
  line-height: 1;
}
.cell[data-c="2"], .cell[data-c="5"] { border-right: 2px solid #26332f; }
.cell[data-c="8"] { border-right: 0; }
.cell[data-r="2"], .cell[data-r="5"] { border-bottom: 2px solid #26332f; }
.cell[data-r="8"] { border-bottom: 0; }

.cell .val { font-family: var(--sans); font-weight: 500; font-variant-numeric: tabular-nums; }
.cell.given .val { color: var(--ink); font-weight: 700; }
.cell.user .val { color: var(--teal); }
.cell.wrong .val { color: var(--err); }
.cell.wrong { background: var(--err-soft); }
.cell.shake { animation: shake .34s cubic-bezier(.36, .07, .19, .97); }

.cell.peer { background: #eff5f3; }
.cell.samenum { background: #e6efec; }
.cell.samenum .val { color: var(--teal-2); }
.cell.given.samenum .val { color: var(--ink); }
.cell.sel { background: var(--teal-soft); }
.cell.sel::after {
  content: ""; position: absolute; inset: 0; border: 2px solid var(--teal-2); pointer-events: none;
}
.cell.hint-target { animation: pulse 1.5s ease-in-out infinite; }
.cell.hint-peer { background: #fdf6e9; }
.cell.hint-elim { background: #fdf0ee; }
.cell.hint-elim::before {
  content: ""; position: absolute; inset: 6px; border: 1.5px dashed rgba(192, 72, 60, .55); border-radius: 6px;
}
.cell.flash { animation: flash .5s ease-out; }
.cell.pop .val { animation: pop .22s cubic-bezier(.2, 1.4, .4, 1); }

.cell .notes {
  position: absolute; inset: 3px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: clamp(8px, 1.3vw, 11px); line-height: 1; color: #6f7d79;
  font-variant-numeric: tabular-nums;
}
.cell .notes span { display: grid; place-items: center; opacity: 0; transition: opacity .1s; }
.cell .notes span.on { opacity: 1; }
.cell .notes span.auto { color: #9dbdb5; }

@keyframes shake {
  10%, 90% { transform: translateX(-1.5px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}
@keyframes pop { from { transform: scale(.55); opacity: .3; } to { transform: scale(1); opacity: 1; } }
@keyframes flash { 0% { background: rgba(20, 134, 123, .28); } 100% { background: transparent; } }
@keyframes pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(14, 107, 99, .55); }
  50% { box-shadow: inset 0 0 0 3px rgba(14, 107, 99, .9); }
}

.board.loading { position: relative; }
.board.loading::after {
  content: attr(data-loading);
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(250, 249, 246, .72); backdrop-filter: blur(1px);
  font-size: 13px; color: var(--ink-soft); letter-spacing: .08em;
  animation: breathe 1.1s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.board.dim .cell { color: transparent; }
.board.dim::after {
  content: "已暂停";
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(250, 249, 246, .93); font-size: 18px; color: var(--ink-soft); letter-spacing: .1em;
}

/* ---------------- number pad ---------------- */
.pad { max-width: 560px; margin-top: 16px; }
.pad-nums { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.pad-actions { display: none; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }

.key {
  position: relative;
  height: 52px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  font-size: 22px; font-weight: 500; color: var(--ink);
  display: grid; place-items: center;
  transition: transform .1s, background .14s, border-color .14s, color .14s;
  box-shadow: var(--shadow-sm);
}
.key:hover { border-color: var(--line-strong); background: #fdfdfb; }
.key:active { transform: scale(.95); }
.key .left {
  position: absolute; top: 6px; right: 7px; font-size: 9px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; letter-spacing: .02em; opacity: .75;
}
.key.done { color: var(--ink-faint); background: var(--paper-2); }
.key .strike { position: absolute; left: 50%; top: 50%; width: 44%; height: 1px; background: var(--ink-faint); transform: translate(-50%, -50%) rotate(-28deg); }

.key-fn {
  height: 42px; border-radius: 11px; border: 1px solid var(--line); background: var(--card);
  font-size: 13px; color: var(--ink-soft); display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: all .14s;
}
.key-fn:hover { border-color: var(--line-strong); color: var(--ink); }
.key-fn.active { background: var(--teal-soft); border-color: rgba(14, 107, 99, .3); color: var(--teal); font-weight: 600; }
.key-fn:active { transform: scale(.97); }

/* ---------------- side ---------------- */
.side { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.card h3 {
  font-size: 11.5px; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-faint);
  font-weight: 600; margin-bottom: 12px;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.stat { text-align: center; padding: 2px 0; }
.stat b { display: block; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat b.err { color: var(--err); }
.stat span { font-size: 11.5px; color: var(--ink-faint); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; border-radius: 11px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; color: var(--ink-soft); font-weight: 500; transition: all .16s; width: 100%;
}
.btn:hover { border-color: var(--line-strong); color: var(--ink); background: #fdfdfb; }
.btn:active { transform: scale(.985); }
.btn kbd {
  font-family: var(--mono); font-size: 10px; color: var(--ink-faint); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 4px; line-height: 15px;
}
.btn.primary {
  background: var(--teal); color: #fff; border-color: var(--teal);
  box-shadow: 0 8px 20px -10px rgba(14, 107, 99, .65); font-weight: 600; height: 44px;
}
.btn.primary:hover { background: #0b5b54; color: #fff; }
.btn.hint { border-style: dashed; color: var(--teal); border-color: rgba(14, 107, 99, .35); }
.btn.hint:hover { background: var(--teal-mist); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.card.actions .btn + .btn-row { margin-top: 8px; }
.card.actions .btn.hint { margin-top: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* levels */
.levels { display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.level {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px; border-radius: 10px; transition: background .14s; text-align: left;
}
.level:hover { background: var(--paper); }
.level.active { background: var(--teal-mist); }
.level .lv-name { font-size: 14px; font-weight: 500; }
.level.active .lv-name { color: var(--teal); font-weight: 600; }
.level .lv-meta { font-size: 11.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.level .lv-best { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }

/* daily */
.daily { position: relative; overflow: hidden; }
.daily-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.daily-date { font-family: var(--serif); font-size: 17px; font-weight: 600; letter-spacing: .01em; }
.daily-sub { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.streak {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  color: var(--amber); background: var(--amber-soft); padding: 4px 9px; border-radius: 999px;
}
.daily-btn {
  width: 100%; height: 38px; border-radius: 10px; border: 1px solid rgba(14, 107, 99, .25);
  background: var(--teal-mist); color: var(--teal); font-size: 13.5px; font-weight: 600; margin-top: 10px;
  transition: all .16s;
}
.daily-btn:hover { background: var(--teal-soft); }
.daily-btn.done { background: var(--paper-2); color: var(--ink-soft); border-color: var(--line); }
.daily-dots { display: flex; gap: 4px; margin-top: 10px; }
.daily-dots i {
  flex: 1; height: 5px; border-radius: 999px; background: var(--paper-2);
}
.daily-dots i.on { background: var(--teal); opacity: .85; }
.daily-dots i.today { background: var(--amber); }

/* records */
.rec-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.rec-row + .rec-row { border-top: 1px dashed var(--line); }
.rec-row .rec-name { color: var(--ink-soft); }
.rec-row .rec-val { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); }
.rec-row .rec-val.empty { color: var(--ink-faint); }

/* ---------------- coach ---------------- */
.coach {
  position: fixed; right: 26px; bottom: 26px;
  width: min(384px, calc(100vw - 40px));
  background: #1f2d2a; color: #eef3f1; border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 24px 48px -18px rgba(20, 40, 36, .6);
  opacity: 0; pointer-events: none; transform: translateY(18px);
  transition: all .28s cubic-bezier(.2, .8, .3, 1);
  z-index: 60;
}
.coach.show { opacity: 1; transform: none; pointer-events: auto; }
.coach .coach-tag {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #7fc3b7; font-weight: 700;
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.coach .coach-text { font-size: 14px; line-height: 1.65; color: #e8efed; }
.coach .coach-actions { display: flex; gap: 8px; margin-top: 12px; }
.coach .coach-actions button {
  font-size: 12.5px; padding: 6px 12px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .18);
  color: #dfe9e6; transition: all .15s;
}
.coach .coach-actions button:hover { background: rgba(255, 255, 255, .1); }
.coach .coach-actions button.solid { background: #7fc3b7; border-color: #7fc3b7; color: #12211e; font-weight: 600; }
.coach .coach-close { position: absolute; top: 10px; right: 12px; color: rgba(255, 255, 255, .4); font-size: 16px; line-height: 1; }

/* ---------------- modal ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(28, 38, 36, .38); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
.modal.show { opacity: 1; pointer-events: auto; }
.modal-card {
  background: var(--card); border-radius: 20px; padding: 26px; width: min(440px, 100%);
  box-shadow: 0 30px 70px -24px rgba(20, 40, 36, .5);
  transform: translateY(10px) scale(.985); transition: transform .26s cubic-bezier(.2, .9, .3, 1);
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.modal.show .modal-card { transform: none; }
.modal-card h2 { font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 6px; }
.modal-card .lead { font-size: 13.5px; color: var(--ink-soft); margin-bottom: 18px; }
.modal-card .big-time {
  font-family: var(--mono); font-size: 40px; letter-spacing: -.02em; color: var(--teal);
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.modal-card .medals { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.medal { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--teal-soft); color: var(--teal); font-weight: 600; }
.medal.gray { background: var(--paper-2); color: var(--ink-soft); font-weight: 500; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.modal-actions .btn-row { margin: 0; }
.rules { font-size: 13.8px; color: var(--ink-soft); line-height: 1.75; }
.rules li { margin-left: 18px; margin-bottom: 6px; }
.rules b { color: var(--ink); font-weight: 600; }
.rules .kbd-line { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.rules .kbd-line span {
  font-size: 11.5px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px; color: var(--ink-soft);
}

/* toast */
.toast {
  position: fixed; left: 50%; top: 22px; transform: translate(-50%, -12px);
  background: #1f2d2a; color: #eef3f1; font-size: 13px; padding: 9px 16px; border-radius: 999px;
  box-shadow: var(--shadow-lift); opacity: 0; transition: all .24s; z-index: 90; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* footer */
.footer {
  margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--ink-faint);
}
.footer a { color: var(--ink-soft); text-decoration: none; border-bottom: 1px solid var(--line); }
.footer a:hover { color: var(--teal); border-color: var(--teal); }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 18px; }
  .side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .side .card.actions { grid-column: 1 / -1; order: -1; }
  .side .card.actions .btn-row,
  .side .card.actions .btn.hint { display: none; }
  .pad-actions { display: grid; }
  .stats { grid-column: 1 / -1; }
  .card.daily { grid-column: auto; }
  .board { max-width: 100%; }
  .pad { max-width: 100%; }
}

@media (max-width: 560px) {
  .app { padding: 0 12px 40px; }
  .topbar { height: 58px; }
  .brand .logo { font-size: 18px; }
  .brand .sub { display: none; }
  .cell { font-size: clamp(18px, 7.4vw, 28px); }
  .cell .notes { font-size: 8px; }
  .key { height: 48px; border-radius: 10px; font-size: 20px; }
  .pad-nums { gap: 4px; }
  .pad-actions { gap: 4px; }
  .key-fn { font-size: 12px; }
  .board-head { margin-bottom: 10px; }
  .side { grid-template-columns: 1fr; }
  .stats { order: -2; }
  .side .card.actions { display: block; order: -1; }
  .side .card.actions .btn.primary { width: 100%; }
  .coach { left: 12px; right: 12px; bottom: 10px; width: auto; }
  .footer { margin-top: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
