:root {
  --blush: #f7dfe3;
  --blush-deep: #eab8c2;
  --rose: #d8798c;
  --rose-dark: #b4566b;
  --ivory: #fffaf3;
  --cream: #fbf1e4;
  --gold: #c9a24b;
  --gold-light: #e8cf8f;
  --sage: #b9cdb4;
  --ink: #5a3f47;
  --ink-soft: #8a6d75;
  --shadow: 0 18px 50px rgba(180, 86, 107, 0.22);
  --script: "Snell Roundhand", "Apple Chancery", "Segoe Script", "Brush Script MT", "Lucida Handwriting", cursive;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.9) 0, transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(232, 207, 143, 0.35) 0, transparent 45%),
    linear-gradient(160deg, var(--blush) 0%, var(--cream) 55%, #f3e6f0 100%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  padding: 10px 16px;
  background: rgba(255, 250, 243, 0.85);
  border: 1px solid var(--gold-light);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(180, 86, 107, 0.12);
  backdrop-filter: blur(6px);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
}

.hud-label {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.hud-value {
  font-size: 1.15rem;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.hud-value.lives {
  color: var(--rose);
  letter-spacing: 2px;
}

.hud-value.lives .lost { color: #e6d3d7; }

.hud-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--gold-light);
  background: var(--ivory);
  color: var(--rose-dark);
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.icon-btn:hover { background: var(--blush); transform: scale(1.06); }
.icon-btn.off { color: #c9b6ba; text-decoration: line-through; }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#game {
  display: block;
  border-radius: 18px;
  box-shadow: var(--shadow), 0 0 0 3px var(--gold-light), 0 0 0 7px var(--ivory);
  background: var(--ivory);
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(247, 223, 227, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s;
  z-index: 5;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.card {
  position: relative;
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 28px 30px 24px;
  text-align: center;
  background: linear-gradient(180deg, #fffdf9, var(--ivory));
  border-radius: 22px;
  border: 1px solid var(--gold-light);
  box-shadow: var(--shadow);
  transform: translateY(14px) scale(0.97);
  transition: transform 0.4s cubic-bezier(.2, .9, .3, 1.3);
}

.card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(201, 162, 75, 0.35);
  border-radius: 16px;
  pointer-events: none;
}

.overlay.show .card { transform: none; }
.card.small { width: min(340px, 100%); }

.rings {
  font-size: 2.4rem;
  animation: float 2.6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.script {
  font-family: var(--script);
  font-weight: normal;
  color: var(--rose-dark);
  margin: 4px 0 2px;
  line-height: 1.15;
}

h1.script { font-size: clamp(2.1rem, 6vw, 2.9rem); }
h2.script { font-size: clamp(1.8rem, 5vw, 2.3rem); }

.subtitle {
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--gold);
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-light), transparent);
}

.card p { line-height: 1.5; margin: 8px 0; }

.howto {
  list-style: none;
  padding: 0;
  margin: 12px 0 18px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.howto li { margin: 7px 0; }
.pink { color: var(--rose); font-weight: bold; }

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  margin: 0 1px;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  background: var(--ivory);
  border: 1px solid var(--gold-light);
  border-bottom-width: 2px;
  border-radius: 5px;
}

.btn {
  display: block;
  width: 100%;
  max-width: 260px;
  margin: 10px auto 0;
  padding: 12px 20px;
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.btn.primary {
  color: #fff;
  border: none;
  background: linear-gradient(135deg, var(--rose), var(--rose-dark));
  box-shadow: 0 8px 20px rgba(180, 86, 107, 0.35), inset 0 0 0 2px rgba(232, 207, 143, 0.6);
}

.btn.primary:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(180, 86, 107, 0.45), inset 0 0 0 2px rgba(232, 207, 143, 0.8); }
.btn.primary:active { transform: translateY(0); }

.btn.ghost {
  color: var(--rose-dark);
  background: transparent;
  border: 1px solid var(--blush-deep);
}

.btn.ghost:hover { background: var(--blush); }

.btn:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.best {
  font-size: 0.85rem;
  color: var(--gold);
  min-height: 1.2em;
}

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 18px;
  max-width: 260px;
  margin: 0 auto 8px;
  text-align: left;
}

.stats dt { color: var(--ink-soft); }
.stats dd { margin: 0; font-weight: bold; text-align: right; font-variant-numeric: tabular-nums; }
.stats .total { color: var(--rose-dark); font-size: 1.1rem; }

.gold { color: var(--gold); font-weight: bold; }

/* ---------- Ring status in HUD ---------- */
.ring-status { color: #c9b6ba; font-size: 0.95rem; }
.ring-status.found { color: var(--gold); }

/* ---------- Setup screens ---------- */
.card.wide { width: min(640px, 100%); }

.options {
  display: grid;
  gap: 12px;
  margin: 4px 0 6px;
}

.options.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.options.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
  font-family: var(--serif);
  color: var(--ink);
  background: #fffdf9;
  border: 1.5px solid var(--blush-deep);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.option:hover { transform: translateY(-2px); border-color: var(--rose); }

.option[aria-checked="true"] {
  background: linear-gradient(180deg, #fff6f8, #fdeef1);
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 75, 0.25), 0 8px 18px rgba(180, 86, 107, 0.18);
}

.option:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.preview {
  width: 100%;
  max-width: 150px;
  aspect-ratio: 3 / 2;
  border-radius: 10px;
  background: linear-gradient(180deg, #fffaf3, #fcefec);
}

.opt-title { font-weight: bold; font-size: 1rem; }
.opt-icon { font-size: 1.5rem; color: var(--rose); letter-spacing: 2px; }
.opt-desc { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.4; }

.guide-title {
  margin: 14px 0 6px;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: normal;
}

.controls-guide {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.guide-col {
  flex: 1 1 200px;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-radius: 14px;
  background: var(--ivory);
  border: 1px dashed var(--gold-light);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.badge.p1 { background: var(--rose); }
.badge.p2 { background: #6f9fb8; }

.keys {
  display: grid;
  grid-template-columns: repeat(3, 30px);
  gap: 3px;
  justify-content: center;
}

.keys kbd {
  min-width: 0;
  width: 30px;
  height: 28px;
  line-height: 24px;
  padding: 0;
  text-align: center;
}

.keys .top { grid-column: 2; }
.keys-or { font-size: 0.75rem; color: var(--gold); }
.keys-pair { display: flex; align-items: center; gap: 8px; }

.row-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

.row-btns .btn { margin: 0; flex: 1 1 0; }

.pause-controls { font-size: 0.85rem; color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 4;
  max-width: calc(100% - 32px);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.95);
  border: 1px solid var(--gold-light);
  color: var(--rose-dark);
  font-size: 0.95rem;
  text-align: center;
  box-shadow: 0 6px 18px rgba(180, 86, 107, 0.2);
  transform: translate(-50%, -8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Touch D-pad ---------- */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 48px);
  grid-template-areas: ". up ." "left down right";
  gap: 6px;
  justify-content: center;
}

.dp {
  border: 1px solid var(--gold-light);
  border-radius: 14px;
  background: rgba(255, 250, 243, 0.9);
  color: var(--rose-dark);
  font-size: 1.1rem;
  touch-action: none;
}

.dp.active { background: var(--blush-deep); }
.dp.up { grid-area: up; }
.dp.down { grid-area: down; }
.dp.left { grid-area: left; }
.dp.right { grid-area: right; }

body.touch .dpad { display: grid; }
body.touch .foot { display: none; }

.foot {
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}

@media (max-width: 560px) {
  .app { padding: 8px 10px; gap: 8px; }
  .hud { border-radius: 18px; gap: 4px 10px; padding: 8px 10px; }
  .hud-item { min-width: 48px; }
  .hud-value { font-size: 1rem; }
  .card { padding: 22px 18px 18px; }
  .options.three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .options.two { grid-template-columns: 1fr; }
  .option { padding: 8px 4px; }
  .opt-title { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .rings { animation: none; }
  .overlay, .card { transition: none; }
}
