* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #12070b;
  color: #f6ecd4;
  font-family: "Noto Sans Khmer", "Khmer Sangam MN", "Khmer OS", "Leelawadee UI", sans-serif;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus { outline: none; }
button:focus-visible { outline: 2px solid #f6e2a8; outline-offset: 2px; }

img, canvas { max-width: 100%; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(168, 36, 64, 0.38), transparent 60%),
    repeating-linear-gradient(45deg, rgba(232, 200, 114, 0.04) 0 8px, transparent 8px 16px),
    repeating-linear-gradient(-45deg, rgba(232, 200, 114, 0.03) 0 8px, transparent 8px 16px),
    #12070b;
}

.spine {
  position: absolute;
  z-index: 5;
  right: 0;
  top: 0;
  bottom: 0;
  width: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 0;
}

.spine::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8%;
  bottom: 8%;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(232, 200, 114, 0.75), transparent);
}

.spine > * { position: relative; z-index: 1; }

.brand-mark {
  margin: 0 0 6px;
  font-family: Palatino, "Palatino Linotype", "Times New Roman", serif;
  letter-spacing: 0.22em;
  font-size: 11px;
  color: #e8c872;
}

.spine button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(232, 200, 114, 0.72);
  background: radial-gradient(circle at 50% 28%, #5a2434, #16080e 72%);
  color: #f6ecd4;
  font-size: 12px;
  line-height: 1.1;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.45), 0 6px 14px rgba(0, 0, 0, 0.35);
}

.spine button.active {
  background: radial-gradient(circle at 50% 28%, #d24b68, #6d1228 74%);
  color: #f8e7b0;
  box-shadow: 0 0 14px rgba(232, 200, 114, 0.45), inset 0 0 0 1px #e8c872;
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-right: 74px;
}

.screen { display: none; min-height: 0; }
.screen.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.screen.scroll.active {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#screen-play {
  width: min(560px, 100%);
  margin: 0 auto;
  gap: 6px;
  padding: 8px 8px 8px;
}

.play-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.titles { min-width: 0; flex: 1; }
.brand-line {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Times New Roman", serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 10px;
  color: #e8c872;
}
.lane-name {
  margin: 0;
  font-size: clamp(13px, 3.6vw, 17px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sound-toggle {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(232, 200, 114, 0.55);
  background: rgba(20, 8, 12, 0.7);
  color: #f6e2a8;
  font-size: 12px;
}

.ribbon {
  display: flex;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
}

.chip {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 14px;
  border: 1px solid rgba(232, 200, 114, 0.35);
  background: #1a0c12;
  overflow: hidden;
  opacity: 0.42;
}
.chip canvas { width: 100%; height: 100%; display: block; }
.chip.now {
  opacity: 1;
  border-color: #f2d48a;
  box-shadow: 0 0 12px rgba(232, 200, 114, 0.45);
}
.chip.done { opacity: 0.9; border-color: #2f8f6e; }

.lane-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  background: #071410;
  border: 1px solid #e8c872;
  box-shadow: inset 0 0 0 4px #1a0a10, inset 0 0 0 5px rgba(232, 200, 114, 0.55), 0 12px 28px rgba(0, 0, 0, 0.4);
}
.lane-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.flag {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  margin: 0;
  max-width: 86%;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(18, 7, 11, 0.86);
  border: 1px solid rgba(232, 200, 114, 0.7);
  color: #f6e2a8;
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}
.flag[hidden] { display: none; }

.veil {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  padding: 12px;
  text-align: center;
  background: linear-gradient(180deg, rgba(8, 3, 6, 0.02) 8%, rgba(8, 3, 6, 0.9) 62%);
}
.veil.show { display: flex; }
.veil-kicker {
  margin: 0;
  color: #e8c872;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.veil h1 {
  margin: 0;
  font-size: clamp(20px, 5.4vw, 30px);
  line-height: 1.25;
  font-weight: 700;
}
.veil p { margin: 0; font-size: 13px; line-height: 1.45; color: #f3e6d0; }
.veil-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.veil-actions button[hidden] { display: none; }

.gold-btn, .ghost-btn {
  min-height: 46px;
  width: 100%;
  border-radius: 999px;
  font-weight: 700;
}
.gold-btn {
  border: 0;
  color: #2a140c;
  background: linear-gradient(180deg, #f8e7b4, #d4a441 52%, #8d6828);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 8px 16px rgba(0, 0, 0, 0.28);
}
.ghost-btn {
  border: 1px solid rgba(232, 200, 114, 0.65);
  background: rgba(18, 7, 11, 0.55);
  color: #f6ecd4;
}

.pads {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding-bottom: max(2px, env(safe-area-inset-bottom));
}
.pads button {
  min-height: 50px;
  border-radius: 16px;
  border: 1px solid rgba(232, 200, 114, 0.7);
  background: linear-gradient(180deg, #6e1830, #3a0d1a);
  color: #f6e2a8;
  font-size: 16px;
  font-weight: 700;
  touch-action: none;
}
.meter { text-align: center; min-width: 76px; }
.meter strong {
  display: block;
  font-size: 20px;
  color: #f6e2a8;
  font-weight: 700;
}
.meter span { display: block; font-size: 11px; color: #d9c7a2; }
.meter.late strong { color: #ffb4c4; }

.sheet {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 12px 12px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.page-head h1 {
  margin: 0;
  font-size: clamp(22px, 6vw, 34px);
  line-height: 1.25;
}
.page-head .brand-mark { margin: 0 0 4px; }
.lede {
  margin: 6px 0 0;
  color: #e6d3b0;
  font-size: 14px;
  line-height: 1.6;
}
.panel {
  position: relative;
  border-radius: 18px;
  border: 1px solid rgba(232, 200, 114, 0.42);
  background: linear-gradient(180deg, rgba(58, 18, 30, 0.94), rgba(16, 6, 10, 0.96));
  padding: 14px 14px 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.panel::before, .panel::after {
  content: "";
  position: absolute;
  width: 46px;
  height: 46px;
  background: url("filigree.png") left top / contain no-repeat;
  opacity: 0.8;
  pointer-events: none;
}
.panel::after { right: 0; left: auto; top: 0; transform: scaleX(-1); }
.panel h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.35;
  padding: 0 28px;
  text-align: center;
}
.panel p {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.65;
  color: #f3e6d0;
}
.panel p:last-child { margin-bottom: 0; }
.panel img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  margin-bottom: 10px;
}
.panel ol {
  margin: 0;
  padding-left: 1.2em;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel li { line-height: 1.55; font-size: 14px; }

.key-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.key-item {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
}
.key-item canvas { width: 48px; height: 48px; }
.key-item span { font-size: 12px; text-align: center; line-height: 1.3; }

.lane-row {
  width: 100%;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid rgba(232, 200, 114, 0.4);
  background: linear-gradient(90deg, rgba(90, 24, 40, 0.55), rgba(16, 6, 10, 0.8));
}
.lane-row > * { min-width: 0; }
.lane-row img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #e8c872;
  background: #1a0a10;
}
.lane-row h2 {
  margin: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lane-row p { margin: 2px 0 0; font-size: 12px; color: #d9c7a2; line-height: 1.35; }
.heat {
  font-size: 12px;
  color: #f6e2a8;
  white-space: nowrap;
}
.lane-row:disabled { opacity: 0.48; }

@media (max-width: 389px), (max-height: 700px) {
  .spine {
    position: relative;
    right: auto;
    top: auto;
    bottom: auto;
    width: auto;
    height: auto;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px 2px;
    gap: 4px;
  }
  .spine::before {
    left: 8%;
    right: 8%;
    top: 58%;
    bottom: auto;
    width: auto;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(232, 200, 114, 0.7), transparent);
  }
  .spine button { width: 40px; height: 40px; font-size: 11px; }
  .brand-mark { margin: 0; font-size: 10px; letter-spacing: 0.12em; }
  .stage { padding-right: 0; }
  .chip { width: 36px; height: 36px; }
}

@media (max-width: 340px) {
  .spine button { width: 34px; height: 34px; font-size: 10px; }
  .chip { width: 32px; height: 32px; border-radius: 10px; }
  .pads button { min-height: 46px; font-size: 15px; }
}

@media (min-width: 420px) {
  .key-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
