:root {
  color-scheme: dark;
  --ink: #fff6df;
  --muted: #cbbf9f;
  --red: #d93c2f;
  --green: #5dbb63;
  --gold: #f2bb3d;
  --panel: rgba(20, 24, 25, 0.78);
  --line: rgba(255, 255, 255, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --edge-gap: 10px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #131614;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
  display: grid;
  align-items: stretch;
  justify-content: stretch;
  background: #090b0b;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: 520px;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: #131614;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 26px 90px rgba(0, 0, 0, 0.55);
  margin: 0 auto;
}

@supports (height: 100dvh) {
  #app {
    height: 100dvh;
    min-height: 100dvh;
    margin: 0 auto;
  }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #202624;
}

.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding:
    calc(24px + var(--safe-top))
    calc(22px + var(--safe-right))
    calc(24px + var(--safe-bottom))
    calc(22px + var(--safe-left));
  background:
    radial-gradient(circle at 50% 22%, rgba(242, 187, 61, 0.2), transparent 34%),
    linear-gradient(180deg, #101412 0%, #070909 100%);
}

.loading-screen:not(.is-visible) {
  display: none;
}

.loading-content {
  width: min(320px, 100%);
  display: grid;
  justify-items: center;
  gap: 18px;
  text-align: center;
}

.loading-symbol {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: clamp(48px, 18vw, 76px);
  font-weight: 900;
  letter-spacing: 0;
  color: rgba(255, 246, 223, 0.34);
  text-shadow: 0 0 0 rgba(242, 187, 61, 0);
  animation: loadingGlow 1.15s ease-in-out infinite;
}

.loading-message {
  color: var(--ink);
  font-size: clamp(20px, 6vw, 27px);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.loading-bar {
  width: 100%;
  height: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.42);
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
  box-shadow: 0 0 18px rgba(242, 187, 61, 0.52);
  transition: width 0.22s ease;
}

@keyframes loadingGlow {
  0%,
  100% {
    color: rgba(255, 246, 223, 0.34);
    text-shadow: 0 0 0 rgba(242, 187, 61, 0);
  }

  45%,
  58% {
    color: #fff6df;
    text-shadow: 0 0 10px rgba(242, 187, 61, 0.92), 0 0 28px rgba(217, 60, 47, 0.42);
  }
}

.hud {
  position: absolute;
  top: calc(var(--edge-gap) + var(--safe-top));
  left: calc(var(--edge-gap) + var(--safe-left));
  right: calc(var(--edge-gap) + var(--safe-right));
  z-index: 3;
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  font-weight: 800;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.8);
}

.hud.is-visible {
  display: grid;
}

.pill {
  min-width: 0;
  padding: 8px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 12, 12, 0.62);
  font-size: clamp(15px, 4vw, 18px);
  line-height: 1;
  white-space: nowrap;
  backdrop-filter: blur(10px);
}

.pill small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
}

.pill:nth-child(2) {
  justify-self: center;
  color: var(--gold);
}

.combo-pill {
  justify-self: center;
  color: #ffffff;
}

.combo-pill.is-hot {
  border-color: rgba(242, 187, 61, 0.86);
  background: rgba(217, 60, 47, 0.72);
  color: #fff6df;
}

.pill:nth-child(4) {
  justify-self: end;
  color: #dcf8db;
}

.hud-button {
  width: 48px;
  min-height: 48px;
  padding: 0;
  pointer-events: auto;
  background: rgba(9, 12, 12, 0.72);
  box-shadow: none;
  font-size: 25px;
  line-height: 1;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  padding:
    calc(18px + var(--safe-top))
    calc(18px + var(--safe-right))
    calc(18px + var(--safe-bottom))
    calc(18px + var(--safe-left));
  background: linear-gradient(rgba(12, 14, 13, 0.18), rgba(12, 14, 13, 0.76));
}

.screen.is-visible {
  display: grid;
}

.menu {
  width: min(420px, 100%);
  margin-top: auto;
  max-height: calc(100dvh - 36px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(14px);
}
.menu h1 {
  text-align: center;
}
.menu h2 {
  text-align: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(34px, 11.8vw, 58px);
  line-height: 0.92;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 5px 0 #64180f, 0 10px 30px rgba(0, 0, 0, 0.72);
  overflow-wrap: anywhere;
  word-break: break-word;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(25px, 8vw, 34px);
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tagline {
  margin: 12px 0 18px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.35;
}

.version-label {
  margin-top: 12px;
  color: rgba(255, 246, 223, 0.56);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--red);
  color: white;
  font: inherit;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 10px 24px rgba(0, 0, 0, 0.28);
}

button:active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 5px 14px rgba(0, 0, 0, 0.32);
}

.options {
  display: grid;
  gap: 10px;
}

.options button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 0 14px;
  text-align: left;
  background: #2f6c68;
  font-size: 17px;
}

.options span {
  justify-self: end;
  color: #f9e6aa;
  font-size: 13px;
  font-weight: 800;
}

.scroll-options {
  max-height: min(52dvh, calc(100dvh - 210px - var(--safe-top) - var(--safe-bottom)), 430px);
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.jarramplas-options button {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 0;
  padding: 8px;
  border: 2px solid rgba(255, 246, 223, 0.18);
  background: rgba(24, 24, 22, 0.78);
}

.jarramplas-options img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

.jarramplas-options {
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
}

.random-jarramplas {
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  padding: 6px;
  background: linear-gradient(135deg, rgba(47, 108, 104, 0.95), rgba(227, 53, 45, 0.82));
}

.random-jarramplas img {
  min-width: 0;
  min-height: 0;
}

.secondary {
  margin-top: 10px;
  background: #3a3a36;
  font-size: 15px;
}

.menu-actions {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.menu-actions .secondary {
  margin-top: 0;
}

.tutorial {
  display: grid;
  gap: 12px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.35;
}

.tutorial strong {
  color: var(--ink);
}

#result .menu,
#stats .menu {
  text-align: center;
}

.scoreline {
  margin: 10px 0 16px;
  color: var(--gold);
  font-size: clamp(42px, 15vw, 72px);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.result-summary {
  display: grid;
  gap: 10px;
  margin: 12px 0 14px;
  text-align: left;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.stat-box {
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 12, 12, 0.48);
  text-align: left;
}

.stat-box strong {
  display: block;
  color: var(--gold);
  font-size: clamp(22px, 8vw, 32px);
  line-height: 1;
}

.stat-box span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-transform: uppercase;
}

.detail-list {
  display: grid;
  gap: 7px;
  margin: 12px 0 14px;
  text-align: left;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
}

.detail-row strong {
  color: var(--ink);
  text-align: right;
  white-space: nowrap;
}

.record-banner {
  margin: 8px 0 10px;
  padding: 10px 12px;
  border: 1px solid rgba(242, 187, 61, 0.38);
  border-radius: 8px;
  background: rgba(242, 187, 61, 0.12);
  color: #ffe7a6;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
  text-transform: uppercase;
}

.record-banner.is-muted {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

#playAgainButton,
#againButton {
  margin-top: 10px;
}

@media (max-width: 380px), (max-height: 700px) {
  :root {
    --edge-gap: 8px;
  }

  .hud {
    gap: 5px;
  }

  .pill {
    padding: 7px 5px;
    font-size: 13px;
  }

  .pill small {
    font-size: 8px;
  }

  .hud-button {
    width: 42px;
    min-height: 42px;
    font-size: 22px;
  }

  .screen {
    padding:
      calc(12px + var(--safe-top))
      calc(12px + var(--safe-right))
      calc(12px + var(--safe-bottom))
      calc(12px + var(--safe-left));
  }

  .menu {
    max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
    padding: 14px;
  }

  h1 {
    font-size: clamp(30px, 10.5vw, 40px);
  }

  h2 {
    font-size: clamp(22px, 7vw, 28px);
  }

  .tagline {
    margin: 10px 0 14px;
    font-size: 14px;
  }

  button {
    min-height: 48px;
    font-size: 16px;
  }

  .options button {
    padding: 0 12px;
    font-size: 15px;
  }
}
