/* ============================================================
   Aiden Soundboard — Minecraft-blocky theme
   Square corners. Hard shadows. Pixel font. No border-radius.
   ============================================================ */

@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/PressStart2P-latin.woff2') format('woff2');
}

:root {
  --grass: #7cbd4b;
  --grass-hi: #a4d872;
  --grass-lo: #5e9a35;
  --dirt: #7a5638;
  --dirt-hi: #9a6e4a;
  --dirt-lo: #4e3116;
  --stone: #8a8a8a;
  --stone-hi: #b5b5b5;
  --stone-lo: #565656;
  --ink: #1d1d1b;
  --line: #2b2b28;
  --red: #e04e39;
  --red-hi: #ff6a4f;
  --yellow: #ffd83d;
  --font: 'Press Start 2P', 'Courier New', monospace;
  --text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.55);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border-radius: 0 !important; /* blocky: never round */
}

html,
body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font);
  background-color: #4a3522;
  background-image: url('textures/dirt.png');
  background-size: 64px 64px;
  image-rendering: pixelated;
  color: #fff;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------------- top bar ---------------- */

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background-image: url('textures/stone.png');
  background-size: 64px 64px;
  background-color: var(--stone-lo);
  border-bottom: 6px solid var(--line);
  box-shadow:
    inset 4px 4px 0 rgba(255, 255, 255, 0.22),
    inset -4px -4px 0 rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 5;
}

.title-wrap {
  margin-right: auto;
  min-width: 0;
}

#topbar h1 {
  font-size: 17px;
  line-height: 1.5;
  color: #fff;
  text-shadow:
    3px 3px 0 var(--line),
    3px 3px 0 var(--line); /* chunky MC title */
  letter-spacing: 1px;
  word-break: break-word;
}

#topbar #subtitle {
  font-size: 9px;
  margin-top: 7px;
  color: #ffffff;
  text-shadow: 2px 2px 0 #000;
}

body.recording #subtitle {
  color: var(--red-hi);
  text-shadow: 2px 2px 0 #000;
  animation: recblink 0.9s steps(2, start) infinite;
}

/* mode toggle = pair of MC buttons */
#modebar {
  display: flex;
  gap: 8px;
}

.mode-btn {
  font-family: var(--font);
  font-size: 10px;
  padding: 12px 12px;
  color: #fff;
  background-color: var(--stone);
  border: 4px solid var(--line);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.35),
    inset -3px -3px 0 rgba(0, 0, 0, 0.4),
    0 5px 0 rgba(0, 0, 0, 0.45);
  cursor: pointer;
  line-height: 1.4;
  min-width: 74px;
  transition: transform 0.05s, box-shadow 0.05s, background-color 0.1s;
}

.mode-btn:active {
  transform: translateY(4px);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.35),
    inset -3px -3px 0 rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(0, 0, 0, 0.45);
}

.mode-btn.on {
  background-color: var(--grass);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.35),
    inset -3px -3px 0 rgba(0, 0, 0, 0.35),
    0 0 0 4px rgba(255, 255, 255, 0.55),
    0 5px 0 rgba(0, 0, 0, 0.45);
}

body[data-mode='rec'] #modeRec.on {
  background-color: var(--red);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.35),
    inset -3px -3px 0 rgba(0, 0, 0, 0.35),
    0 0 0 4px rgba(255, 255, 255, 0.55),
    0 5px 0 rgba(0, 0, 0, 0.45);
}

/* REC banner while recording */
#recbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background-color: var(--line);
  border: 4px solid var(--line);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.12),
    inset -3px -3px 0 rgba(0, 0, 0, 0.5);
  order: 3;
  width: 100%;
}

#recbar[hidden] {
  display: none;
}

.rec-dot {
  width: 16px;
  height: 16px;
  background-color: var(--red-hi);
  flex: 0 0 auto;
  animation: recblink 0.8s steps(2, start) infinite;
}

@keyframes recblink {
  to {
    visibility: hidden;
  }
}

#recTimer {
  font-size: 14px;
  color: #fff;
  text-shadow: var(--text-shadow);
}

#btnStopRec {
  font-family: var(--font);
  font-size: 12px;
  padding: 8px 16px;
  margin-left: auto;
  color: #fff;
  background-color: var(--red);
  border: 3px solid var(--line);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

/* ---------------- board grid ---------------- */

#board {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(148px, 1fr);
  gap: 14px;
  padding: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 780px) and (min-aspect-ratio: 3/4) {
  #board {
    grid-template-columns: repeat(4, 1fr);
  }
}

.slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  min-height: 0;
  font-family: var(--font);
  border: 4px solid var(--line);
  cursor: pointer;
  padding: 6px;
  overflow: hidden;
  transition: transform 0.05s, box-shadow 0.05s;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* empty slot = dark stone */
.slot.empty {
  background-image: url('textures/stone.png');
  background-size: 64px 64px;
  background-color: var(--stone-lo);
  box-shadow:
    inset 4px 4px 0 rgba(0, 0, 0, 0.4),
    inset -4px -4px 0 rgba(255, 255, 255, 0.12),
    0 6px 0 rgba(0, 0, 0, 0.4);
}

.slot.filled {
  background-image: url('textures/grass.png');
  background-size: 64px 64px;
  background-color: var(--grass);
  box-shadow:
    inset 4px 4px 0 rgba(255, 255, 255, 0.4),
    inset -4px -4px 0 rgba(0, 0, 0, 0.28),
    0 6px 0 rgba(0, 0, 0, 0.45);
}

.slot:active {
  transform: translateY(5px);
}

.slot.filled:active {
  box-shadow:
    inset 4px 4px 0 rgba(255, 255, 255, 0.4),
    inset -4px -4px 0 rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(0, 0, 0, 0.45);
}

/* playing feedback: gold pulsing frame + pressed */
.slot.playing {
  transform: translateY(5px);
  box-shadow:
    inset 4px 4px 0 rgba(255, 255, 255, 0.4),
    inset -4px -4px 0 rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(0, 0, 0, 0.45),
    0 0 0 4px var(--yellow),
    0 0 0 8px rgba(0, 0, 0, 0.55);
}

/* currently-recording slot: red frame + pulse */
.slot.rec-active {
  box-shadow:
    inset 4px 4px 0 rgba(255, 255, 255, 0.25),
    inset -4px -4px 0 rgba(0, 0, 0, 0.35),
    0 0 0 4px var(--red-hi),
    0 0 0 9px rgba(0, 0, 0, 0.6);
  animation: recframe 0.7s steps(2, start) infinite;
}

@keyframes recframe {
  to {
    box-shadow:
      inset 4px 4px 0 rgba(255, 255, 255, 0.25),
      inset -4px -4px 0 rgba(0, 0, 0, 0.35),
      0 0 0 4px #fff,
      0 0 0 9px rgba(0, 0, 0, 0.6);
  }
}

body[data-mode='rec'] .slot.empty {
  cursor: pointer;
}

/* dim other slots while recording */
body.recording .slot:not(.rec-active) {
  opacity: 0.45;
  pointer-events: none;
}

.slot .big-plus {
  font-size: 30px;
  color: #f2f2f2;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  line-height: 1;
}

.slot .slot-hint {
  font-size: 9px;
  line-height: 1.6;
  text-align: center;
  color: #f0f0f0;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.7);
}

.slot.filled .slot-hint {
  color: #245e0f;
  text-shadow: none;
}

/* label text */
.slot-label {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  color: #fff;
  text-shadow:
    2px 2px 0 var(--line),
    2px 2px 0 var(--line);
  max-width: 100%;
  padding: 0 2px;
}

.slot-label.long {
  font-size: 9px;
  line-height: 1.8;
}

.slot-label.xlong {
  font-size: 8px;
  line-height: 2;
}

/* keep label clear of NAME/DEL chips in edit mode */
body[data-mode='rec'] .slot.filled .slot-label {
  margin-top: 14px;
}

.slot-label.long {
  font-size: 8px;
}

.slot-label.recording-text {
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

/* chips (rename / delete) — appear in REC mode on filled slots */
.chip-row {
  position: absolute;
  top: 2px;
  right: 2px;
  display: none;
  gap: 4px;
  z-index: 3;
}

body[data-mode='rec'] .slot.filled .chip-row {
  display: flex;
}

.chip {
  font-family: var(--font);
  font-size: 9px;
  line-height: 1;
  padding: 6px 7px;
  border: 2px solid var(--line);
  cursor: pointer;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
}

.chip.rename {
  background-color: var(--stone-hi);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.4), inset -2px -2px 0 rgba(0, 0, 0, 0.3);
}

.chip.del {
  background-color: var(--red);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.4), inset -2px -2px 0 rgba(0, 0, 0, 0.3);
}

.chip.armed {
  background-color: var(--yellow);
  color: #000;
  text-shadow: none;
  outline: 2px solid #fff;
  outline-offset: -1px;
}

/* REC overlay text inside recording slot */
.rec-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  position: absolute;
  inset: 0;
  background: rgba(70, 4, 4, 0.72);
  justify-content: center;
  z-index: 2;
}

.slot.rec-active .rec-overlay {
  display: flex;
}

.rec-overlay .dot {
  width: 20px;
  height: 20px;
  background: var(--red-hi);
  animation: recblink 0.6s steps(2, start) infinite;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.5);
}

.rec-overlay span {
  font-size: 10px;
  color: #fff;
  text-shadow:
    2px 2px 0 #000,
    2px 2px 0 #000;
  text-align: center;
  line-height: 1.7;
  padding: 0 4px;
}

/* ---------------- footer hint ---------------- */

#hintbar {
  flex: 0 0 auto;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background-image: url('textures/dirt.png');
  background-size: 64px 64px;
  background-color: var(--dirt-lo);
  border-top: 6px solid var(--line);
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.14),
    inset 0 -4px 0 rgba(0, 0, 0, 0.3);
}

#hint {
  font-size: 9px;
  line-height: 1.8;
  text-align: center;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
}

#renamebar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 560px;
}

#renamebar[hidden] {
  display: none;
}

#renameInput {
  flex: 1 1 auto;
  font-family: var(--font);
  /* >=16px so iOS Safari does not auto-zoom on focus */
  font-size: 16px;
  color: #fff;
  background-color: var(--stone-lo);
  border: 3px solid var(--line);
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.5);
  padding: 8px;
  min-width: 0;
  user-select: text;
  -webkit-user-select: text;
}

#renamebar button {
  font-family: var(--font);
  font-size: 11px;
  padding: 0 14px;
  color: #fff;
  border: 3px solid var(--line);
  cursor: pointer;
}

#renameOk {
  background-color: var(--grass);
}

#renameCancel {
  background-color: var(--stone);
}

/* ---------------- toast ---------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background-color: var(--ink);
  border: 3px solid #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 9px;
  line-height: 1.6;
  padding: 10px 14px;
  max-width: min(92vw, 520px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 50;
}

#toast.show {
  opacity: 1;
}

/* keep tiny screens usable */
@media (max-width: 420px) {
  #topbar h1 {
    font-size: 13px;
  }
  .slot .slot-label {
    font-size: 9px;
  }
}
