.audio-retry {
  margin-top: 18px;
  border: 1px solid #ffe69d;
  border-radius: 11px;
  padding: 10px 14px;
  background: #ffffff1c;
  color: #fff1be;
  font-weight: 800;
}

.board-cell {
  background: linear-gradient(145deg, #413180, #2b1d66);
  box-shadow: inset 0 2px 3px #09052255, inset 0 0 0 1px #ffffff10;
}

.tile,
.mini-tile {
  border: 1px solid #ffffff42;
  background-color: var(--color);
  background-image:
    radial-gradient(circle at 81% 24%, #ffffff8c 0 2%, transparent 4%),
    radial-gradient(circle at 22% 73%, #ffffff2d 0 7%, transparent 9%),
    radial-gradient(circle at 79% 77%, #ffffff30 0 12%, transparent 15%),
    linear-gradient(160deg, color-mix(in srgb, var(--color) 68%, white) 0%, var(--color) 42%, var(--shade) 100%);
  box-shadow:
    inset 0 3px 1px #ffffff91,
    inset 0 -5px 0 #36104a2e,
    0 3px 5px #0b053b77;
}

.tile {
  border-radius: 11px;
}

.tile::before,
.mini-tile::before {
  content: "";
  position: absolute;
  top: 11%;
  left: 12%;
  width: 34%;
  height: 17%;
  border-radius: 70% 35% 80% 35%;
  background: #fffdf6;
  transform: rotate(-27deg);
  box-shadow: 11px 6px 0 -5px #fff9;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(circle at 31% 32%, #ffffffb0 0 1.5%, transparent 3%),
    radial-gradient(circle at 65% 54%, #ffffff30 0 4%, transparent 6%),
    radial-gradient(circle at 38% 85%, #ffffff38 0 5%, transparent 7%),
    linear-gradient(#ffffff28, transparent 38%, #81174b16 75%);
}

.tile.selected {
  box-shadow:
    inset 0 0 0 3px #fffdf5,
    inset 0 3px 1px #ffffff91,
    inset 0 -5px 0 #36104a2e,
    0 0 10px #fff7b266,
    0 3px 5px #0b053b77;
}

.mini-tile {
  border-radius: 4px;
  box-shadow: inset 0 2px 0 #ffffffa0, inset 0 -2px 0 #0002, 0 1px 2px #0b053b77;
}

.mini-tile::before {
  top: 12%;
  left: 13%;
  width: 38%;
  height: 18%;
  box-shadow: none;
}

@media (orientation: landscape) and (max-height: 550px) and (max-width: 1000px) {
  :root {
    --board-size: min(
      calc(100dvh - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
      calc(55vw - 20px),
      480px
    );
  }

  .app {
    width: min(100%, 1100px);
    padding: env(safe-area-inset-top) 14px env(safe-area-inset-bottom);
  }

  .screen { padding: 8px 0; }

  .home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: repeat(4, auto);
    column-gap: clamp(18px, 5vw, 70px);
    align-content: center;
    text-align: left;
  }
  .home-art { display: none; }
  .home .kicker { grid-column: 1; grid-row: 1; align-self: end; }
  .home h1 {
    grid-column: 1;
    grid-row: 2 / 5;
    align-self: start;
    font-size: clamp(3.5rem, 8vw, 6rem);
    margin: 10px 0;
  }
  .home-description { grid-column: 2; grid-row: 1; margin: 0 0 12px; }
  .home-actions { grid-column: 2; grid-row: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); min-width: 0; width: min(100%, 360px); }
  .home-actions .button { min-height: 44px; }
  .home-actions .button-large { min-height: 52px; }
  .audio-retry { grid-column: 2; grid-row: 3; margin-top: 10px; }
  .progress-copy { grid-column: 2; grid-row: 4; margin: 12px 0 0; }

  .page-header h2 { font-size: 1.6rem; }
  .levels-intro { margin: 8px 2px 12px; }
  .level-grid {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 7px;
    max-width: 820px;
    margin: 0 auto;
  }
  .level-button { font-size: 1.1rem; border-radius: 12px; }

  .game {
    display: grid;
    grid-template-columns: var(--board-size) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto 1fr;
    column-gap: 18px;
    row-gap: 6px;
    align-content: start;
  }
  .game-header { grid-column: 1 / -1; grid-row: 1; }
  .board-wrap { grid-column: 1; grid-row: 2 / 7; align-self: start; }
  .stats { grid-column: 2; grid-row: 2; margin: 0; }
  .status { grid-column: 2; grid-row: 3; margin: 0; min-height: 24px; }
  .controls { grid-column: 2; grid-row: 4; margin: 14px 0 18px; }
  .tray-heading { grid-column: 2; grid-row: 5; margin: 0 2px; }
  .tray {
    grid-column: 2;
    grid-row: 6;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 0;
    align-content: start;
  }
  .tray-piece { min-height: 52px; }
  .mini-shape { transform: scale(.78); }

  .modal {
    padding: calc(8px + env(safe-area-inset-top)) 12px
      calc(8px + env(safe-area-inset-bottom));
  }
  .dialog {
    width: min(100%, 520px);
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 16px 20px;
  }
  .dialog h2 { font-size: 1.55rem; margin-bottom: 8px; }
  .dialog-emoji { font-size: 2rem; margin: 0; }
  .dialog p { margin: 8px 0; }
  .settings-row { margin: 8px 0; }
  .help-steps { margin: 8px 0; }
  .help-steps li { margin: 4px 0; }
}

@media (orientation: landscape) and (max-height: 430px) and (max-width: 1000px) {
  .game { row-gap: 4px; }
  .game-header .icon-button,
  .page-header .icon-button { width: 42px; height: 42px; }
  .game-header h2 { font-size: 1.35rem; }
  .stat { min-height: 42px; }
  .stat strong { font-size: 1rem; }
  .status { min-height: 18px; font-size: .7rem; }
  .controls { gap: 5px; margin: 6px 0 8px; }
  .control-button { min-height: 44px; }
  .control-button small { display: none; }
  .tray { gap: 5px; align-self: start; grid-auto-rows: 64px; height: max-content; }
  .tray-piece { min-height: 50px; }
  .tray-heading h3 { font-size: .85rem; }
  .tray-heading span { font-size: .68rem; }
  .home h1 { font-size: clamp(3.1rem, 7vw, 5rem); }
  .home-description { font-size: .95rem; }
  .home-actions { gap: 8px; }
  .home-actions .button-secondary { padding: 0 3px; font-size: .82rem; overflow-wrap: anywhere; }
  .progress-copy { margin-top: 8px; }
  .dialog { padding: 12px 18px; }
  .dialog-emoji { display: none; }
  .dialog h2 { margin: 0 36px 6px; }
  .dialog p { font-size: .85rem; line-height: 1.25; margin: 4px 0; }
  .dialog .button { min-height: 44px; margin-top: 6px; }
  .settings-row { padding: 6px 10px; margin: 6px 0; }
  .toggle { min-height: 36px; }
  .help-steps { font-size: .82rem; line-height: 1.3; padding-left: 18px; margin: 14px 0 6px; }
  .help-steps li { margin: 3px 0; }
}

@media (orientation: landscape) and (max-height: 550px) and (max-width: 500px) {
  .level-grid { gap: 5px; }
  .tray { align-self: start; grid-auto-rows: 50px; height: max-content; }
  .mini-shape { transform: scale(.6); }
}

@media (orientation: landscape) and (max-height: 350px) and (max-width: 1000px) {
  .tray { grid-auto-rows: 50px; }
}

@media (orientation: landscape) and (max-height: 550px) and (max-width: 440px) {
  .level-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}

@media (orientation: portrait) and (max-width: 560px) {
  .control-button { flex-direction: column; gap: 1px; min-height: 62px; }
  .control-button small { max-width: 100%; font-size: .7rem; line-height: 1.1; white-space: nowrap; }
}

.language-select {
  width: min(58%, 210px);
  min-height: 42px;
  border: 1px solid #ffffff70;
  border-radius: 12px;
  padding: 0 8px;
  background: #37227f;
  color: #fff;
  font: inherit;
  font-weight: 750;
}


.tray-piece {
  display: flex;
  align-items: center;
  justify-content: center;
  border-color: #ffffff3c;
  background: radial-gradient(circle at 50% 0, #a58af04d, transparent 72%), linear-gradient(145deg, #46318d, #2a1c67);
  box-shadow: inset 0 2px 0 #ffffff24, 0 3px 0 #120a43;
}

.tray-piece.selected {
  border-color: #fff1a4;
  background: radial-gradient(circle at 50% 0, #ffe78857, transparent 72%), linear-gradient(145deg, #6044a5, #332277);
  box-shadow: inset 0 2px 0 #ffffff57, 0 0 12px #ffe26c66, 0 3px 0 #120a43;
}

.tray-piece .mini-shape { flex: none; }
