:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #62676f;
  --paper: #e6dcc7;
  --panel: #f4ecda;
  --line: #cbbfa9;
  --green: #1f9d72;
  --red: #e5524d;
  --teal: #0d9fb3;
  --gold: #d8a21b;
  --black: #202124;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 42px;
  padding: 0 14px;
}

button:hover,
button.active {
  border-color: var(--black);
  box-shadow: inset 0 0 0 1px var(--black);
}

.icon-btn {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  position: relative;
}

.btn-icon {
  display: block;
  fill: currentColor;
  height: 24px;
  width: 24px;
}

.control-btn,
.share-btn,
.modal-action-btn,
.modal-close-btn {
  border-radius: 999px;
  height: 54px;
  min-height: 54px;
  padding: 0;
  width: 54px;
}

.start-action-btn {
  height: 64px;
  min-height: 64px;
  width: 64px;
}

.btn-badge,
.btn-hotkey,
.shop-price {
  align-items: center;
  background: rgba(244, 236, 218, 0.96);
  border: 1px solid currentColor;
  border-radius: 999px;
  box-shadow: 0 6px 14px rgba(32, 33, 36, 0.12);
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 800;
  justify-content: center;
  line-height: 1;
  min-width: 18px;
  padding: 3px 6px;
  position: absolute;
}

.btn-badge {
  bottom: -4px;
  right: -4px;
}

.btn-hotkey {
  left: -4px;
  top: -4px;
}

.app {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  min-height: 520px;
  overflow: hidden;
  position: relative;
}

.topbar {
  align-items: center;
  background: transparent;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 12px clamp(14px, 4vw, 44px);
  position: absolute;
  pointer-events: none;
  right: 0;
  top: 0;
  z-index: 10;
}

.hud {
  display: grid;
  flex: 1 1 auto;
  gap: 8px;
  margin: 0 auto;
  max-width: 820px;
  width: 100%;
}

.eyebrow {
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 3rem);
  line-height: 1;
  margin: 0;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.stats span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: nowrap;
}

.hud-toast {
  align-self: start;
  background: rgba(244, 236, 218, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(32, 33, 36, 0.12);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  justify-self: start;
  max-width: min(520px, 100%);
  padding: 8px 12px;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.hud-toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}

.speed-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.speed-btn {
  background: #efe4bf;
  border-color: #cbb67e;
}

.speed-btn {
  border-radius: 999px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  width: 48px;
}

.swatch {
  border-radius: 99px;
  display: inline-block;
  height: 14px;
  width: 30px;
}

.playfield {
  grid-row: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.side-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: absolute;
  top: 18px;
  z-index: 4;
}

.side-controls-left {
  left: 18px;
}

.side-controls-right {
  right: 18px;
}

.side-controls-left button,
.side-controls-left .speed-btn {
  background: #efe4bf;
  border-color: #cbb67e;
  box-shadow: 0 10px 28px rgba(32, 33, 36, 0.14);
}

.side-controls-right button {
  background: #dcebdc;
  border-color: #9fbea0;
  box-shadow: 0 10px 28px rgba(32, 33, 36, 0.14);
}

.remove-btn.active {
  background: #f4d4cb;
  border-color: #e5524d;
  color: #202124;
}

.speed-picker-vertical {
  flex-direction: column;
  flex-wrap: nowrap;
}

.side-controls .speed-btn,
.side-controls button {
  min-width: 0;
}

.music-toggle {
  min-width: 0;
}

#gameCanvas {
  cursor: pointer;
  display: block;
  height: 100%;
  touch-action: none;
  width: 100%;
}

.notice {
  background: rgba(244, 236, 218, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(32, 33, 36, 0.13);
  left: clamp(14px, 4vw, 44px);
  max-width: min(430px, calc(100vw - 28px));
  padding: 16px;
  pointer-events: none;
  position: absolute;
  top: 18px;
  transition: opacity 180ms ease, transform 180ms ease;
}

.inventory {
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: absolute;
  right: 18px;
  z-index: 3;
}

.inventory-btn {
  border-radius: 999px;
  height: 58px;
  box-shadow: 0 10px 28px rgba(32, 33, 36, 0.14);
  min-height: 58px;
  padding: 0;
  width: 58px;
}

.inventory-btn.warn {
  animation: inventoryWarn 520ms ease;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 82, 77, 0.22), 0 10px 28px rgba(32, 33, 36, 0.14);
}

@keyframes inventoryWarn {
  0%,
  100% {
    transform: translateX(0);
  }

  28% {
    transform: translateX(-5px);
  }

  56% {
    transform: translateX(5px);
  }
}

.notice.hidden {
  opacity: 0;
  transform: translateY(-10px);
}

.notice h2 {
  font-size: 1.1rem;
  margin: 0 0 8px;
}

.notice p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.start-modal {
  align-items: center;
  background: rgba(230, 220, 199, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 12px;
  position: absolute;
  z-index: 7;
}

.start-modal.hidden {
  display: none;
}

.start-card {
  align-items: center;
  background: rgba(244, 236, 218, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 56px rgba(32, 33, 36, 0.18);
  display: grid;
  gap: 10px;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  justify-items: center;
  max-height: min(680px, calc(var(--viewport-height, 100dvh) - 24px));
  max-width: min(420px, calc(100vw - 24px));
  overflow: hidden;
  padding: 18px 22px;
  text-align: center;
  width: 100%;
}

.start-brand {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.start-mark {
  display: block;
  height: 58px;
  width: 87px;
}

.start-copy h2 {
  font-size: clamp(0.95rem, 1.8vw, 1.25rem);
  line-height: 1;
  margin: 0;
}

.start-copy .eyebrow {
  font-size: clamp(1.2rem, 2.4vw, 1.65rem);
  margin-bottom: 6px;
}

.field {
  display: grid;
  gap: 6px;
  text-align: left;
  width: 100%;
}

.field span {
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 700;
}

.field input {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}

.field input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 159, 179, 0.16);
  outline: none;
}

.field-hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: -6px 0 0;
  min-height: 1.2em;
  text-align: left;
  width: 100%;
}

.field-hint.error {
  color: var(--red);
}

.leaderboard-panel {
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(32, 33, 36, 0.12);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  min-height: 0;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.leaderboard-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.leaderboard-head h3 {
  font-size: 1rem;
  margin: 0;
}

.leaderboard-status {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.leaderboard-list {
  display: grid;
  gap: 5px;
  max-height: min(250px, 30vh);
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.leaderboard-empty {
  color: var(--muted);
  font-size: 0.94rem;
  margin: 0;
}

.leaderboard-row {
  align-items: center;
  border: 1px solid rgba(32, 33, 36, 0.12);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  min-height: 32px;
  padding: 5px 10px;
}

.leaderboard-row.current-player {
  border-color: rgba(13, 159, 179, 0.5);
  box-shadow: 0 0 0 2px rgba(13, 159, 179, 0.12);
}

.leaderboard-rank {
  color: var(--muted);
  font-weight: 700;
}

.leaderboard-name {
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-meta {
  display: none;
}

.leaderboard-score {
  font-size: 0.95rem;
  font-weight: 800;
}

.results-modal {
  align-items: center;
  background: rgba(230, 220, 199, 0.82);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: absolute;
  z-index: 6;
}

.results-modal.hidden {
  display: none;
}

.shop-modal {
  align-items: center;
  background: rgba(230, 220, 199, 0.76);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: absolute;
  z-index: 8;
}

.shop-modal.hidden {
  display: none;
}

.shop-card {
  background: rgba(244, 236, 218, 0.97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 56px rgba(32, 33, 36, 0.18);
  display: grid;
  gap: 16px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 20px;
  width: 100%;
}

.shop-head {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.shop-head h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  line-height: 1;
  margin: 0;
}

.shop-items {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-items: center;
}

.shop-item-btn {
  background: #dcebdc;
  border-color: #9fbea0;
  border-radius: 999px;
  height: 78px;
  min-height: 78px;
  padding: 0;
  width: 78px;
}

.shop-item-btn .btn-icon {
  height: 28px;
  width: 28px;
}

.shop-item-btn.unaffordable {
  opacity: 0.72;
}

.shop-price {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
}

.start-card .modal-action-btn,
.results-card .modal-action-btn {
  justify-self: center;
}

.modal-close-btn {
  height: 46px;
  min-height: 46px;
  width: 46px;
}

.results-card {
  background: rgba(244, 236, 218, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 56px rgba(32, 33, 36, 0.18);
  max-width: min(520px, calc(100vw - 36px));
  padding: 22px;
  width: 100%;
}

.results-card h2 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  margin: 0 0 18px;
}

.results-stats {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.results-stats span {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

.share-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-items: center;
  margin-bottom: 12px;
}

.leaderboard-panel-results {
  margin-bottom: 12px;
}

@media (pointer: coarse) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    height: var(--viewport-height, 100dvh);
    min-height: 0;
  }

  .topbar {
    left: 0;
    position: fixed;
    right: 0;
    top: var(--viewport-top, 0px);
  }

  .start-modal,
  .results-modal,
  .shop-modal {
    height: var(--viewport-height, 100dvh);
    left: 0;
    position: fixed;
    right: 0;
    top: var(--viewport-top, 0px);
  }
}

@media (pointer: coarse) and (max-width: 960px) {
  .topbar {
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 0;
  }

  .hud {
    gap: 6px;
    margin: 0;
    max-width: none;
  }

  .stats {
    gap: 6px;
    justify-content: center;
  }

  .stats span {
    font-size: 0.82rem;
    padding: 6px 8px;
  }

  .hud-toast {
    font-size: 0.8rem;
    max-width: min(360px, calc(100vw - 20px));
    padding: 6px 10px;
  }

  .side-controls {
    gap: 6px;
  }

  .side-controls-left {
    left: 10px;
  }

  .side-controls-right {
    right: 10px;
  }

  .control-btn {
    height: 46px;
    min-height: 46px;
    width: 46px;
  }

  .speed-btn {
    font-size: 0.9rem;
    height: 42px;
    min-height: 42px;
    min-width: 48px;
    padding: 0 10px;
    width: auto;
  }

  .inventory-btn {
    height: 50px;
    min-height: 50px;
    width: 50px;
  }

  .btn-icon {
    height: 20px;
    width: 20px;
  }

  .start-modal,
  .results-modal,
  .shop-modal {
    padding: 12px;
  }

  .start-card,
  .results-card,
  .shop-card {
    max-height: calc(var(--viewport-height, 100dvh) - 24px);
    max-width: min(460px, calc(100vw - 24px));
    padding: 16px;
  }

  .start-mark {
    height: 56px;
    width: 84px;
  }

  .start-copy .eyebrow {
    font-size: clamp(1.05rem, 4vw, 1.45rem);
    margin-bottom: 6px;
  }

  .start-copy h2 {
    font-size: clamp(0.9rem, 3vw, 1.1rem);
  }

  .leaderboard-panel {
    padding: 10px;
  }

  .leaderboard-list {
    max-height: min(220px, 26vh);
  }

  .share-actions,
  .shop-items {
    gap: 10px;
  }

  .shop-item-btn {
    height: 70px;
    min-height: 70px;
    width: 70px;
  }

  .shop-item-btn .btn-icon {
    height: 24px;
    width: 24px;
  }

  .modal-action-btn,
  .share-btn {
    height: 50px;
    min-height: 50px;
    width: 50px;
  }

  .start-action-btn {
    height: 58px;
    min-height: 58px;
    width: 58px;
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  .topbar {
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 0;
  }

  .hud {
    gap: 4px;
  }

  .stats {
    gap: 4px;
  }

  .stats span {
    font-size: 0.74rem;
    padding: 4px 6px;
  }

  .side-controls {
    gap: 4px;
    top: calc(var(--viewport-top, 0px) + env(safe-area-inset-top, 0px) + 10px);
  }

  .side-controls-left {
    left: 8px;
  }

  .side-controls-right {
    right: 8px;
  }

  .control-btn {
    height: 38px;
    min-height: 38px;
    width: 38px;
  }

  .speed-btn {
    font-size: 0.78rem;
    height: 34px;
    min-height: 34px;
    min-width: 38px;
    padding: 0 6px;
  }

  .inventory {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    gap: 4px;
    right: 8px;
  }

  .inventory-btn {
    height: 40px;
    min-height: 40px;
    width: 40px;
  }

  .btn-icon {
    height: 16px;
    width: 16px;
  }

  .btn-badge,
  .btn-hotkey,
  .shop-price {
    font-size: 0.6rem;
    min-width: 14px;
    padding: 2px 4px;
  }

  .start-card,
  .results-card,
  .shop-card {
    max-height: calc(var(--viewport-height, 100dvh) - 20px);
    max-width: min(880px, calc(100vw - 20px));
    padding: 14px;
  }

  .start-card {
    align-items: start;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
    grid-template-areas:
      "brand leaderboard"
      "field leaderboard"
      "hint leaderboard"
      "start leaderboard";
    height: 100%;
    justify-items: stretch;
    min-height: 0;
    text-align: left;
  }

  .start-brand {
    gap: 8px;
    grid-area: brand;
    justify-items: start;
  }

  .field {
    grid-area: field;
  }

  .field-hint {
    grid-area: hint;
  }

  .start-card .leaderboard-panel {
    align-self: stretch;
    grid-template-rows: auto minmax(0, 1fr);
    grid-area: leaderboard;
    height: 100%;
    min-height: 0;
  }

  .start-card .leaderboard-list {
    align-content: start;
    height: 100%;
    max-height: none;
  }

  .start-card #startBtn {
    grid-area: start;
    justify-self: start;
  }

  .results-card {
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
    grid-template-areas:
      "eyebrow leaderboard"
      "title leaderboard"
      "stats leaderboard"
      "shares leaderboard"
      "restart leaderboard";
    height: 100%;
    min-height: 0;
  }

  .results-card .eyebrow {
    grid-area: eyebrow;
  }

  .results-card h2 {
    grid-area: title;
    margin: 0;
  }

  .results-stats {
    grid-area: stats;
    margin-bottom: 0;
  }

  .share-actions {
    grid-area: shares;
    margin-bottom: 0;
  }

  .leaderboard-panel-results {
    align-self: stretch;
    grid-template-rows: auto minmax(0, 1fr);
    grid-area: leaderboard;
    height: 100%;
    margin-bottom: 0;
    min-height: 0;
  }

  .leaderboard-panel-results .leaderboard-list {
    align-content: start;
    height: 100%;
    max-height: none;
  }

  .results-card #resultsRestartBtn {
    grid-area: restart;
    justify-self: start;
  }

  .shop-card {
    align-items: start;
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
    grid-template-areas: "head items";
    height: auto;
  }

  .shop-head {
    grid-area: head;
  }

  .shop-items {
    grid-area: items;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  .topbar {
    padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  }

  .side-controls {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    flex-direction: row;
    top: auto;
  }

  .speed-picker-vertical {
    flex-direction: row;
  }

  .stats {
    justify-content: flex-start;
  }

  .side-controls-left,
  .side-controls-right {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  }

  .inventory {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 60px);
    flex-direction: row;
    gap: 6px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}
