/* Gemensam stil. Skriven för Safari 12: ingen gap i flexbox, inga min()/clamp()/inset. */
:root {
  --bg: #0d0b1f;
  --bg2: #1a1540;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f1ff;
  --muted: #a49cc8;
  --accent: #8b6cff;
  --accent2: #3ee0b0;
  --warn: #ffb648;
  --bad: #ff4d6d;
  --vh: 100vh;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background: radial-gradient(ellipse 120% 70% at 50% 0%, #2a1f63 0%, var(--bg) 70%) no-repeat, var(--bg);
}

a { color: inherit; text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.btn {
  display: inline-block;
  padding: 14px 26px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 6px 20px rgba(139, 108, 255, 0.35);
  -webkit-transition: -webkit-transform 0.1s;
  transition: transform 0.1s;
}
.btn:active { -webkit-transform: scale(0.96); transform: scale(0.96); }
.btn.ghost { background: var(--panel2); box-shadow: none; }
.btn + .btn { margin-left: 10px; }

/* ---------- Spelsidor ---------- */
body.game {
  height: var(--vh);
  overflow: hidden;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  /* Extra luft i nederkant: iOS 12 räknar ibland höjden några pixlar för högt i hemskärmsläget */
  padding: var(--top) 16px 14px;
  padding-bottom: calc(var(--bottom) + 14px);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.bar {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  height: 64px;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}
.bar h1 {
  -webkit-flex: 1;
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.02em;
}
.bar .back, .bar .actions { width: 160px; }
.bar .back {
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 0;
}
.bar .actions { text-align: right; white-space: nowrap; }

.icon-btn {
  display: inline-block;
  width: 44px;
  height: 44px;
  margin-left: 6px;
  border-radius: 12px;
  background: var(--panel);
  vertical-align: middle;
  line-height: 0;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .when-off { display: none; }
.icon-btn.off .when-on { display: none; }
.icon-btn.off .when-off { display: inline; }
.icon-btn.off svg { stroke: var(--muted); }

.scores {
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  margin-bottom: 12px;
}
.score {
  min-width: 110px;
  margin: 0 6px;
  padding: 8px 16px;
  border-radius: 14px;
  background: var(--panel);
  text-align: center;
  position: relative;
}
.score span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.score b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }

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

/* Overlay över spelplanen: start, paus, game over */
.overlay {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  text-align: center;
  background: rgba(13, 11, 31, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 18px;
  opacity: 0;
  visibility: hidden;
  -webkit-transition: opacity 0.2s, visibility 0.2s;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 10;
  padding: 20px;
}
.overlay.show { opacity: 1; visibility: visible; }
.overlay h2 { margin: 0 0 8px; font-size: 40px; }
.overlay p { margin: 0 0 22px; color: var(--muted); font-size: 18px; line-height: 1.4; }
.overlay .record { color: var(--warn); font-weight: 700; }
.overlay .hint { margin-top: 18px; margin-bottom: 0; font-size: 15px; }

/* Instruktioner (?-knappen) */
.help {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 50;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 20px;
  background: rgba(13, 11, 31, 0.8);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  -webkit-transition: opacity 0.2s, visibility 0.2s;
  transition: opacity 0.2s, visibility 0.2s;
}
.help.show { opacity: 1; visibility: visible; }
.help-box {
  width: 100%;
  max-width: 560px;
  max-height: 86%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 26px;
  border-radius: 20px;
  background: var(--bg2);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  text-align: left;
}
.help-box h2 { margin: 0 0 14px; font-size: 26px; }
.help-box h3 { margin: 18px 0 6px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent2); }
.help-box p, .help-box li { color: #d9d4f5; font-size: 17px; line-height: 1.5; }
.help-box p { margin: 0 0 8px; }
.help-box ul { margin: 0; padding-left: 20px; }
.help-box li { margin-bottom: 6px; }
.help-box b { color: var(--text); }
.help-box .btn { display: block; width: 100%; margin-top: 20px; text-align: center; }
