:root {
  --bg-top: #eef3f4;
  --bg-bottom: #e7e3ef;
  --panel: #fcfbf8;
  --line: rgba(51, 61, 77, 0.14);
  --text: #222d38;
  --muted: #5b6670;
  --accent: #4b6fb8;
  --accent-dark: #334f8b;
  --board-bg: #1f2837;
  --board-line: rgba(255, 255, 255, 0.08);
  --shadow: 0 14px 34px rgba(33, 48, 58, 0.1);
  --radius: 26px;
  --board-radius: 28px;
  --cell-size: min(3.75vh, 37px);
  --font-main: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
  min-height: 100vh;
  overflow: hidden;
}

.reload-hotspot {
  position: fixed;
  top: 0;
  right: 0;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  opacity: 0.01;
  z-index: 20;
}

.page-shell {
  width: min(1920px, 100vw);
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 10px 32px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(315px, 390px) minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 32px);
}

.panel-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.side-main {
  display: grid;
  gap: 12px;
  align-content: start;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-dark);
  font-size: 0.85rem;
  font-weight: 700;
}

.brand-block h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 4vw, 4.6rem);
  line-height: 0.9;
}

button {
  border: none;
  border-radius: 18px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  padding: 15px 16px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
  touch-action: manipulation;
  user-select: none;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.02);
  outline: none;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 16px 26px rgba(75, 111, 184, 0.25);
}

.secondary-button,
.control-button {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(33, 48, 58, 0.06);
}

.exit-link {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  min-height: 66px;
  border-radius: 18px;
  background: linear-gradient(180deg, #455560, #29353d);
  color: #ffffff;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: 0 12px 22px rgba(33, 48, 58, 0.2);
}

.exit-link:hover,
.exit-link:focus-visible {
  filter: brightness(1.04);
  outline: none;
}

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

.stats-card h2,
.info-card h2,
.next-panel h2 {
  font-size: 1.1rem;
  margin: 0 0 8px;
}

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

.stat-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  padding: 10px 12px;
  min-width: 0;
}

.stat-label {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-box strong {
  font-size: 1.45rem;
  line-height: 1;
}

.info-card p,
.status-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.info-card p + p {
  margin-top: 8px;
}

.board-panel {
  display: grid;
  overflow: hidden;
}

.game-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 280px);
  gap: 18px;
  align-items: stretch;
  width: 100%;
  min-height: 100%;
}

.play-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size));
  grid-template-rows: repeat(20, var(--cell-size));
  gap: 2px;
  padding: 12px;
  border-radius: var(--board-radius);
  background: linear-gradient(180deg, #263246, var(--board-bg));
  border: 4px solid rgba(75, 111, 184, 0.28);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.cell,
.next-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.045);
  box-shadow: inset 0 0 0 1px var(--board-line);
}

.next-panel {
  width: min(100%, 180px);
  padding: 14px;
  border-radius: 22px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 10px 22px rgba(33, 48, 58, 0.08);
}

.next-board {
  display: grid;
  grid-template-columns: repeat(4, calc(var(--cell-size) * 0.9));
  grid-template-rows: repeat(4, calc(var(--cell-size) * 0.9));
  gap: 2px;
  justify-content: center;
  padding: 8px;
  border-radius: 16px;
  background: #253046;
}

.next-cell {
  width: calc(var(--cell-size) * 0.9);
  height: calc(var(--cell-size) * 0.9);
}

.piece-i { background: linear-gradient(180deg, #75ddf5, #28a7c4); }
.piece-j { background: linear-gradient(180deg, #78a9ff, #3766cc); }
.piece-l { background: linear-gradient(180deg, #ffc46d, #db7d20); }
.piece-o { background: linear-gradient(180deg, #ffe784, #d7b829); }
.piece-s { background: linear-gradient(180deg, #8be184, #3eaa3f); }
.piece-t { background: linear-gradient(180deg, #c891ff, #864acc); }
.piece-z { background: linear-gradient(180deg, #ff8c9b, #cf334d); }

.control-pad {
  align-self: end;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.control-button {
  min-height: 92px;
  padding: 10px;
  font-size: 2.7rem;
  line-height: 1;
  touch-action: none;
}

.control-button:active {
  transform: translateY(1px) scale(0.98);
}

.control-primary {
  background: linear-gradient(180deg, #ffffff, #e9eef8);
}

@media (max-width: 1280px) {
  :root {
    --cell-size: min(3.4vh, 33px);
  }

  .game-area {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 250px);
  }
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .layout,
  .game-area {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .actions-block,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .control-pad {
    max-width: 520px;
    width: 100%;
    justify-self: center;
  }
}

@media (max-width: 720px) {
  :root {
    --cell-size: min(7.2vw, 30px);
  }

  .page-shell {
    width: min(100%, calc(100% - 16px));
    padding: 10px 8px;
  }

  .panel-card {
    padding: 16px;
  }

  .play-wrap {
    flex-direction: column;
    align-items: center;
  }
}
