:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #151a24;
  --border: #2a3142;
  --text: #e6e8ee;
  --accent: #7dd3fc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: "Courier New", Consolas, monospace;
}

.wrap {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  padding: 24px;
}

.touch-hint { display: none; }

h1 {
  position: absolute;
  transform: translateY(-52px);
  letter-spacing: 0.3em;
  font-size: 20px;
  margin: 0;
  color: var(--accent);
}

.game {
  position: relative;
  border: 4px solid var(--border);
  border-radius: 4px;
  background: #000;
  line-height: 0;
}

canvas#board {
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}

.overlay[hidden] { display: none; }

.overlay p {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.overlay .hint {
  font-size: 13px;
  color: var(--text);
  letter-spacing: normal;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 140px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: #8b93a7;
  font-weight: normal;
  text-transform: uppercase;
}

.panel p {
  margin: 2px 0;
  font-size: 16px;
}

.panel canvas {
  display: block;
  background: #000;
  border-radius: 2px;
}

.controls p {
  font-size: 12px;
  color: #b7bccb;
}

.touch-controls {
  display: none;
}

@media (max-width: 680px), (pointer: coarse) {
  html, body {
    min-height: 100vh;
    min-height: 100dvh;
  }

  body {
    overflow-y: auto;
    justify-content: flex-start;
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .wrap {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    flex-direction: column;
    align-items: center;
    padding: 0;
    gap: 6px;
  }

  h1 {
    position: static;
    transform: none;
    flex: 0 0 auto;
    font-size: 15px;
    margin: 0;
  }

  .side {
    flex: 0 0 auto;
    width: 100%;
    max-width: 320px;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .side .panel {
    flex: 1 1 auto;
    padding: 5px 8px;
    min-width: 0;
  }

  .side .panel h2 {
    font-size: 9px;
    margin: 0 0 2px;
  }

  .side .panel p {
    font-size: 14px;
  }

  .side .panel:first-child {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .side .panel:first-child h2 {
    display: none;
  }

  .side .panel:first-child canvas {
    width: 32px;
    height: 32px;
  }

  .game {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  canvas#board {
    height: 100%;
    width: auto;
    max-width: 100%;
    aspect-ratio: 1 / 2;
  }

  .desktop-hint { display: none; }
  .touch-hint { display: inline; }

  .touch-controls {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 44px);
    gap: 8px;
    width: 100%;
    max-width: 320px;
  }

  .tbtn {
    font-size: 20px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .tbtn:active {
    background: var(--border);
  }

  #btnPause {
    font-size: 16px;
  }
}

@media (max-height: 600px) and (max-width: 680px) {
  .side .panel:not(:first-child) { display: none; }
  .touch-controls { grid-template-rows: repeat(2, 38px); }
}
