:root {
  --ink: #10172f;
  --muted: #7b86a0;
  --blue: #3478f6;
  --blue-soft: #e7efff;
  --panel: #eef3ff;
  --line: #d9e3f7;
  --danger: #ed3d2f;
  --paper: #fff;
  --shadow: 0 18px 60px rgba(39, 61, 111, .14);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: #f6f8fe;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
body { min-height: 100svh; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid rgba(52,120,246,.3); outline-offset: 3px; }

.game-shell {
  width: min(100%, 760px);
  height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--paper);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sitebar {
  min-height: 42px;
  padding: max(9px, env(safe-area-inset-top)) 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #fff;
  border-bottom: 1px solid #e5eaf4;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  z-index: 3;
}
.brand { color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 750; }
.topnote { color: var(--muted); font-size: 10px; letter-spacing: .12em; white-space: nowrap; }
.brand:hover { color: var(--blue); }

.topbar {
  min-height: 88px;
  padding: 10px 20px 11px;
  display: grid;
  grid-template-columns: 50px 1fr 50px;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, #e9effd 0%, #edf2ff 100%);
  border-bottom: 1px solid #d8e2f6;
  z-index: 2;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.94);
  color: var(--blue);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(74, 104, 166, .09), 0 8px 24px rgba(41, 72, 138, .07);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { transform: translateY(1px) scale(.97); }

.status-block { text-align: center; line-height: 1.05; }
.difficulty-label {
  color: var(--blue);
  font-size: clamp(22px, 4.5vw, 32px);
  font-weight: 950;
  letter-spacing: .02em;
}
.status-row {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  font-weight: 900;
}
.hearts { color: var(--danger); font-size: 23px; letter-spacing: 2px; min-width: 80px; }
.timer { display: inline-flex; align-items: center; gap: 5px; font-size: 20px; font-variant-numeric: tabular-nums; }

.board-card {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  isolation: isolate;
}
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.board-card.shake { animation: shake .22s linear 1; }
.board-card.busy #gameCanvas { cursor: default; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

.toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -5px);
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(16,23,47,.91);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  white-space: nowrap;
  z-index: 4;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.tutorial {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(88%, 420px);
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 1px solid rgba(214,225,246,.85);
  border-radius: 24px;
  background: rgba(255,255,255,.98);
  box-shadow: 0 20px 70px rgba(31,52,96,.22);
  text-align: center;
  display: grid;
  gap: 10px;
  z-index: 6;
}
.tutorial[hidden] { display: none !important; }
.tutorial strong { font-size: 18px; line-height: 1.5; }
.tutorial span { color: var(--muted); line-height: 1.55; font-size: 14px; }
.tutorial button, .primary-btn, .secondary-btn {
  min-height: 48px;
  border-radius: 15px;
  font-weight: 900;
  cursor: pointer;
}
.tutorial button, .primary-btn { border: 0; background: var(--blue); color: #fff; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(238,243,255,.78);
  backdrop-filter: blur(10px);
}
.overlay[hidden] { display: none !important; }
.overlay-card {
  width: min(100%, 430px);
  padding: 28px;
  border-radius: 28px;
  background: rgba(255,255,255,.98);
  box-shadow: 0 28px 90px rgba(30,54,110,.20);
  text-align: center;
  border: 1px solid rgba(218,227,246,.9);
}
.overlay-kicker { color: var(--blue); font-weight: 950; letter-spacing: .14em; font-size: 11px; }
.overlay h1 { margin: 8px 0 9px; font-size: 30px; letter-spacing: -.02em; }
.overlay p { color: var(--muted); line-height: 1.6; margin: 0 0 19px; font-size: 14px; }

.difficulty-grid { display: grid; gap: 10px; }
.difficulty-grid[hidden] { display: none !important; }
.difficulty-btn {
  min-height: 68px;
  border: 1px solid #dbe5f7;
  border-radius: 18px;
  background: #f8faff;
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
  text-align: left;
  padding: 0 16px;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}
.difficulty-btn:hover { transform: translateY(-1px); border-color: #b9cdf5; background: #f3f7ff; }
.difficulty-btn:active { transform: translateY(0) scale(.99); }
.difficulty-btn strong { color: var(--blue); font-size: 18px; }
.difficulty-btn span { color: var(--muted); font-size: 13px; line-height: 1.4; }

.result-actions { display: grid; gap: 10px; }
.result-actions[hidden] { display: none !important; }
.primary-btn, .secondary-btn { width: 100%; }
.secondary-btn { border: 1px solid #d9e3f7; background: #f8faff; color: #5f6e8d; }

.toolbar {
  min-height: 102px;
  padding: 12px 18px max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 11px;
  background: linear-gradient(180deg, #edf2ff 0%, #e8eefc 100%);
  border-top: 1px solid #d8e2f6;
  z-index: 2;
}
.tool-btn {
  position: relative;
  min-height: 70px;
  border: 0;
  border-radius: 20px;
  background: rgba(255,255,255,.94);
  color: var(--blue);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  box-shadow: 0 4px 0 rgba(74,104,166,.09);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tool-btn:disabled { opacity: .48; cursor: default; }
.tool-btn:not(:disabled):active { transform: translateY(1px) scale(.98); }
.tool-icon { font-size: 27px; line-height: 1; font-weight: 900; }
.tool-name { font-size: 11px; font-weight: 850; color: #68748f; }
.tool-count {
  position: absolute;
  right: 9px;
  top: 7px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #ffd954;
  color: #725400;
  font-size: 11px;
  font-weight: 950;
}

@media (max-width: 520px) {
  .sitebar { min-height: 38px; padding: max(7px, env(safe-area-inset-top)) 13px 6px; }
  .topnote { font-size: 9px; }
  .topbar { min-height: 82px; grid-template-columns: 44px 1fr 44px; padding-left: 13px; padding-right: 13px; }
  .icon-btn { width: 43px; height: 43px; font-size: 20px; }
  .difficulty-label { font-size: 24px; }
  .hearts { font-size: 21px; min-width: 74px; }
  .timer { font-size: 18px; }
  .toolbar { min-height: 94px; padding-left: 10px; padding-right: 10px; gap: 8px; }
  .tool-btn { min-height: 66px; border-radius: 18px; }
  .tool-icon { font-size: 25px; }
  .overlay { padding: 18px; }
  .overlay-card { padding: 24px 20px; border-radius: 24px; }
}
