﻿html, body { margin:0; height:100%; overflow:hidden; background:transparent; }
* { box-sizing: border-box; }

:root {
  --bg1: #EAF4EF;
  --bg2: #D7E8E2;
  --bg3: #C6DDD6;
  --text: #1A1D2B;
  --muted: rgba(26, 29, 43, 0.65);
  --glass: rgba(255, 255, 255, 0.35);
  --glass-strong: rgba(255, 255, 255, 0.5);
  --cell-empty: #F4F8F6;
  --ok: rgba(46, 204, 113, 0.35);
  --fail: rgba(229, 83, 61, 0.35);
  --block-1: #6B8F71;
  --block-2: #6FA3C8;
  --block-3: #D88C6A;
  --block-4: #E2C57E;
  --block-5: #9C8FD6;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
}

.app {
  width: 100%;
  height: 100%;
  position: relative;
  background: linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 45%, var(--bg3) 100%);
}
.app::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 50% at 50% 0%, rgba(255,255,255,0.65) 0%, rgba(255,255,255,0.08) 70%),
    linear-gradient(180deg, rgba(234,244,239,0.35) 0%, rgba(198,221,214,0.5) 100%),
    url("bg.jpg") center / cover no-repeat;
}
.screen,
.rotate-hint,
.overlay {
  z-index: 1;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
}
.start-screen.active { display: block; }
.game-screen.active { display: grid; }

.start-screen { padding: 18px; }
.top-right {
  position: absolute;
  top: 14px;
  right: 14px;
}
.start-content {
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
}
.brand-lockup {
  display: grid;
  justify-items: center;
  gap: 10px;
}
.brand-mark {
  width: clamp(180px, 32vw, 360px);
  max-height: 120px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(26, 29, 43, 0.08));
}
.logo {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  color: #4e7d63;
  letter-spacing: 0.02em;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.45rem);
}
.start-btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 34px;
  min-width: 220px;
  background: rgba(255, 248, 236, 0.9);
  color: #2a6447;
  font-size: 1.4rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
}

.game-screen {
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}
.brand-mini {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #3f7f64;
  letter-spacing: 0.02em;
}
.brand-mark-mini {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: none;
}
.topbar-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}
.score-pill {
  justify-self: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.45);
  color: #2e6e58;
  font-size: 1.05rem;
}
.score-pill strong {
  margin-left: 6px;
  font-size: 1.2rem;
}

.icon-btn {
  border: 1px solid rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.5);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.9rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.icon-btn:active { transform: translateY(1px); }
.icon-only {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}
.sound-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #3a715b;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.muted .wave { opacity: 0; }
.sound-icon .mute-line { opacity: 0; }
.icon-btn.muted .mute-line { opacity: 1; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.game-main {
  width: min(98vw, 1100px);
  height: calc(100vh - 84px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.board-wrap {
  width: min(calc(100vh - 120px), calc(100vw - 280px));
  max-width: none;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  border: 1px solid var(--glass-strong);
  background: var(--glass);
  box-shadow: 0 20px 60px rgba(0,0,0,0.08);
  padding: clamp(8px, 1.7vw, 12px);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 120ms ease-out;
}
@supports not ((backdrop-filter: blur(2px))) {
  .board-wrap { background: rgba(255,255,255,0.85); }
}
.board-wrap.place-pulse { transform: scale(1.02); }

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: clamp(3px, 0.7vw, 6px);
}
.cell {
  border-radius: 8px;
  background: var(--cell-empty);
  transition: transform 180ms ease, opacity 180ms ease, background-color 120ms ease;
}
.cell.filled { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35); }
.cell.c1, .piece-cell.c1 { background: var(--block-1); }
.cell.c2, .piece-cell.c2 { background: var(--block-2); }
.cell.c3, .piece-cell.c3 { background: var(--block-3); }
.cell.c4, .piece-cell.c4 { background: var(--block-4); }
.cell.c5, .piece-cell.c5 { background: var(--block-5); }
.cell.ghost-ok { background: var(--ok); }
.cell.ghost-fail { background: var(--fail); }
.cell.clearing { transform: scale(0.75); opacity: 0.1; }
@supports (background: color-mix(in srgb, #000 50%, white 50%)) {
  .cell.c1, .piece-cell.c1 { background: color-mix(in srgb, var(--block-1) 88%, white 12%); }
  .cell.c2, .piece-cell.c2 { background: color-mix(in srgb, var(--block-2) 88%, white 12%); }
  .cell.c3, .piece-cell.c3 { background: color-mix(in srgb, var(--block-3) 88%, white 12%); }
  .cell.c4, .piece-cell.c4 { background: color-mix(in srgb, var(--block-4) 88%, white 12%); }
  .cell.c5, .piece-cell.c5 { background: color-mix(in srgb, var(--block-5) 88%, white 12%); }
}

.tray {
  width: 100%;
  height: min(calc(100vh - 120px), 560px);
  margin: 0 auto;
  border-radius: 18px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.38);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.piece-slot {
  min-height: 84px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.piece-slot.empty { opacity: 0.35; }
.piece-card {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: grid;
  gap: 4px;
}
.piece-cell {
  width: clamp(14px, 2.1vw, 22px);
  height: clamp(14px, 2.1vw, 22px);
  border-radius: 5px;
}
.piece-cell.on { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25); }
.piece-cell.off { background: transparent; }

.drag-piece {
  position: fixed;
  z-index: 99;
  pointer-events: none;
  opacity: 0.92;
  transform: translate(-50%, -50%) scale(1.06);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.overlay.active { display: flex; }

.end-card {
  width: min(92vw, 420px);
  border-radius: 20px;
  padding: 18px;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.end-card h2 { margin: 0 0 10px; }
.end-line { margin: 7px 0; color: #244733; }
.end-actions {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}
.primary-btn, .secondary-btn {
  border: 0;
  border-radius: 12px;
  padding: 12px;
  font-size: 1rem;
}
.primary-btn {
  background: #3f7f64;
  color: #fff;
}
.secondary-btn {
  background: rgba(255,255,255,0.72);
  color: #204030;
}

.rotate-hint {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 120;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.rotate-card {
  background: rgba(255,255,255,0.9);
  border-radius: 14px;
  padding: 14px 18px;
  color: #234735;
  font-weight: 600;
}

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint { display: flex; }
  .screen { pointer-events: none; }
}

@media (max-width: 980px) and (orientation: landscape) {
  .game-main {
    grid-template-columns: minmax(0, 1fr) 180px;
    gap: 8px;
  }
  .board-wrap {
    width: min(calc(100vh - 112px), calc(100vw - 220px));
  }
  .tray {
    height: min(88vh, 460px);
    padding: 8px;
    gap: 8px;
  }
}
