:root {
  --accent: #2b9b9b;
  --accent-2: #37b1b1;
  --text: #2f4646;
  --line: #245252;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #d6f3f3 0%, #e3ecff 55%, #ffe9f2 100%);
  background-attachment: fixed;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px); gap: 12px; }
.topbar { width: 100%; max-width: 560px; display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 22px; font-weight: 800; margin: 0; color: var(--accent); text-shadow: 0 2px 0 #fff; }
.back-btn, .sound-toggle {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: none;
  background: #fff; color: var(--accent); box-shadow: var(--shadow);
  font-size: 20px; font-weight: 800; text-decoration: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.back-btn:active, .sound-toggle:active { transform: scale(0.92); }
.sound-toggle.off { opacity: 0.5; }
.hud { width: 100%; max-width: 560px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hud-item { background: #fff; border-radius: 999px; padding: 8px 16px; font-size: 15px; font-weight: 700; box-shadow: var(--shadow); color: #4a6a6a; }
.hud-item b { color: var(--accent); font-size: 17px; }
.mini-btn { border: none; background: var(--accent); color: #fff; font-weight: 800; border-radius: 999px; padding: 9px 16px; font-size: 14px; cursor: pointer; box-shadow: var(--shadow); }
.mini-btn:first-of-type { margin-left: auto; }
.mini-btn:active { transform: scale(0.95); }

.board-area { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; width: 100%; }
.sudoku { display: grid; width: min(94vw, 66vh, 470px); background: var(--line); border: 3px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.scell { background: #fff; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-weight: 800; cursor: pointer; border: 1px solid #d2e6e6; color: var(--accent);
  font-size: clamp(17px, 5.5vw, 30px); line-height: 1; }
.scell.given { color: #233; background: #eef5f5; }
.scell.sel { background: #fff2bf; box-shadow: inset 0 0 0 2px var(--accent); }
.scell.bad { color: #e0524f !important; background: #ffe2e0; }
.scell.bR { border-right: 3px solid var(--line); }
.scell.bB { border-bottom: 3px solid var(--line); }

.palette { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 470px; }
.pbtn { width: 46px; height: 46px; border-radius: 12px; border: 2px solid #c4e2e2; background: #fff;
  font-size: 22px; font-weight: 800; color: var(--accent); cursor: pointer; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; }
.pbtn.erase { color: #e08a3c; border-color: #f2d6b8; }
.pbtn:active { transform: scale(0.93); background: var(--accent); color: #fff; }

.overlay { position: fixed; inset: 0; background: rgba(25, 45, 45, 0.45); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.overlay[hidden] { display: none; }
.card-panel { background: #fff; border-radius: 26px; padding: 26px 22px; width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: center; }
.card-panel h2 { margin: 0 0 10px; font-size: 24px; color: var(--accent); }
.card-panel p { margin: 4px 0 18px; color: #4a6a6a; font-weight: 600; }
.win-emoji { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
.field { text-align: left; margin-bottom: 18px; }
.field > label { display: block; font-size: 14px; color: #4a6a6a; font-weight: 700; margin-bottom: 8px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-btn { flex: 1; min-width: 64px; border: 2px solid #c4e2e2; background: #f0fafa; color: var(--text); padding: 12px 8px; border-radius: 14px; font-size: 15px; font-weight: 700; cursor: pointer; }
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.big-btn { width: 100%; border: none; border-radius: 16px; padding: 16px; margin-top: 6px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow); }
.big-btn:active { transform: scale(0.97); background: var(--accent-2); }
.big-btn.ghost { background: #fff; color: var(--accent); border: 2px solid #c4e2e2; box-shadow: none; margin-top: 10px; }
