* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-family: system-ui, sans-serif;
  background: #1e1f26;
  color: #e8e8ee;
}

h1 {
  margin: 8px 0 0;
  font-size: 1.8rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

select,
button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #2c2e38;
  color: inherit;
  cursor: pointer;
}

button:hover {
  background: #3a3d4a;
}

canvas {
  background: #f4f1e8;
  border-radius: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  max-width: 100%;
}

.hint {
  margin: 0;
  color: #aaa;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid #666;
  border-bottom-width: 3px;
  border-radius: 4px;
  background: #2c2e38;
  font-family: inherit;
  font-size: 0.9em;
}

.message {
  font-size: 1.3rem;
  font-weight: bold;
  color: #6ee38a;
}

.scores {
  width: 100%;
  max-width: 600px;
  margin-top: 8px;
}

.scores h2 {
  margin: 0;
  font-size: 1.2rem;
}

dialog {
  border: 1px solid #555;
  border-radius: 10px;
  padding: 20px 24px;
  background: #262833;
  color: inherit;
  max-width: calc(100vw - 32px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog h2 {
  margin: 0;
  font-size: 2rem;
  text-align: center;
  color: #6ee38a;
}

dialog .result {
  font-size: 1.2rem;
  text-align: center;
}

#dialogText:empty {
  display: none;
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

dialog label {
  display: flex;
  align-items: center;
  gap: 10px;
}

dialog p {
  margin: 0;
}

input[type="text"] {
  font: inherit;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #2c2e38;
  color: inherit;
  width: 140px;
}

table {
  width: 100%;
  margin: 10px 0;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid #383a46;
}

th {
  color: #aaa;
  font-weight: 600;
}

tr.latest td {
  background: rgba(110, 227, 138, 0.15);
  color: #6ee38a;
  font-weight: bold;
}

td.empty {
  color: #777;
  text-align: center;
  font-style: italic;
}

button.small {
  font-size: 0.85rem;
  padding: 4px 10px;
}

.hidden {
  display: none;
}

/* ----- Touch controls ----- */
body {
  overscroll-behavior: none; /* no pull-to-refresh while swiping down */
}

canvas {
  -webkit-user-select: none;
  user-select: none;
}

button,
select {
  touch-action: manipulation; /* no double-tap zoom on buttons */
}

.dpad {
  display: none;
  grid-template-areas:
    ".    up    ."
    "left down  right";
  grid-template-columns: repeat(3, 88px);
  grid-template-rows: repeat(2, 88px);
  gap: 8px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.dpad button {
  font-size: 2.2rem;
  padding: 0;
  border-radius: 16px;
  touch-action: none;
}

.dpad button.pressed {
  background: #4a4e60;
}

.dpad .up { grid-area: up; }
.dpad .down { grid-area: down; }
.dpad .left { grid-area: left; }
.dpad .right { grid-area: right; }

.touch-hint {
  display: none;
}

/* Show touch controls on phones/tablets (finger is the main pointer) */
@media (pointer: coarse) {
  body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  input {
    -webkit-user-select: text;
    user-select: text;
  }
  .dpad {
    display: grid;
  }
  .touch-hint {
    display: block;
  }
  .key-hint {
    display: none;
  }
  select,
  button {
    padding: 10px 16px; /* bigger tap targets */
  }
}

.version {
  margin-top: 8px;
  font-size: 0.75rem;
  color: #666;
}

/* Full-screen layer for the win confetti (clicks pass straight through) */
.confetti {
  background: transparent; /* override the cream background all canvases get */
  box-shadow: none;
  border-radius: 0;
  max-width: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}
