:root {
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
  --walnut-dark: #120A06;
  --walnut-mid: #1E130D;
  --walnut-light: #2B1A11;
  --brass-hi: #FFE28A;
  --brass-mid: #C8943E;
  --brass-lo: #6E4A16;
  --ivory: #FFF4D6;
  --cyan: #3DF5FF;
  --amber: #FFB830;
  --magenta: #FF4FD8;
  --crimson: #FF4242;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #1A100B;
  color: var(--ivory);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.hidden {
  display: none !important;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  padding-top: var(--sat);
  padding-bottom: var(--sab);
  overflow: hidden;
  background: #1A100B;
}

/* Top Bezel: exact 36px height */
#top-bezel {
  flex: 0 0 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 8px;
  background: linear-gradient(180deg, #271810 0%, #170D08 100%);
  border-bottom: 1px solid #4A311C;
  z-index: 20;
  touch-action: none;
}

.bezel-left, .bezel-center, .bezel-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border-radius: 5px;
  border: 1px solid #6E4A16;
  background: #1E130D;
  color: var(--ivory);
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.back-link:hover {
  border-color: var(--brass-hi);
  color: var(--brass-hi);
}

.marble-sockets {
  display: flex;
  align-items: center;
  gap: 4px;
}

.socket {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--brass-mid);
  background: #120A06;
  display: inline-block;
}

.socket.filled {
  background: radial-gradient(circle at 35% 30%, #FFFFFF 0%, #D9DEE6 55%, #7E8796 100%);
  border-color: var(--brass-hi);
}

.bridge-mods {
  display: flex;
  align-items: center;
  gap: 3px;
}

.mod-pip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--brass-mid);
  background: #2C1D11;
  color: var(--brass-hi);
}

.mod-pip.gold {
  border-color: #FFD86B;
  color: #FFD86B;
  background: #1B1733;
}

.brass-plate {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  padding: 2px 6px;
  border-radius: 4px;
  background: #1E130D;
  border: 1px solid #7C5420;
  color: var(--brass-hi);
  white-space: nowrap;
}

.score-plate {
  color: var(--ivory);
  min-width: 44px;
  text-align: right;
}

.chime-pips {
  display: flex;
  align-items: center;
  gap: 3px;
}

.chime-pip {
  width: 8px;
  height: 8px;
  clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
  background: #3A271A;
}

.chime-pip.alive {
  background: #FFD54F;
}

.chime-pip.golden {
  background: #FFD86B;
}

.bezel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid #7C5420;
  background: linear-gradient(180deg, #3A2516 0%, #21140C 100%);
  color: var(--brass-hi);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 180ms ease;
}

.bezel-btn:active {
  transform: scale(0.93);
}

.bezel-btn.spinning {
  transform: rotate(-360deg);
}

/* Playfield Wrapper */
#playfield-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #140C07;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Overlays inside playfield-wrap */
.banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 20px);
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #FFB830;
  background: rgba(24, 14, 9, 0.94);
  color: #FFE28A;
  font-size: 12px;
  font-weight: 600;
}

.banner-close {
  border: none;
  background: transparent;
  color: #FFE28A;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
}

.overlay-actions {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 12;
}

.brass-cta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.08em;
  padding: 11px 22px;
  border-radius: 8px;
  border: 1.5px solid var(--brass-hi);
  background: linear-gradient(180deg, #4A3018 0%, #24160C 100%);
  color: var(--brass-hi);
  cursor: pointer;
  min-height: 44px;
}

.brass-cta.primary {
  background: linear-gradient(180deg, #F5C451 0%, #B87B24 100%);
  color: #1A100B;
  border-color: #FFF4D6;
}

.brass-cta.small {
  padding: 7px 12px;
  font-size: 11px;
  min-height: 34px;
}

.brass-cta:active {
  transform: scale(0.96);
}

.tray-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 7, 4, 0.78);
  z-index: 14;
  padding: 12px;
}

.tray-panel {
  width: min(360px, 100%);
  padding: 14px;
  border-radius: 10px;
  border: 1.5px solid #96682B;
  background: linear-gradient(180deg, #2B1A11 0%, #190F09 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.tray-panel.compact {
  width: min(260px, 100%);
}

.tray-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tray-choices {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tray-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 4px;
  border-radius: 8px;
  border: 1px solid #6E4A16;
  background: #170E09;
  color: var(--ivory);
  cursor: pointer;
}

.tray-card:hover {
  border-color: var(--brass-hi);
}

.tray-preview {
  width: 72px;
  height: 72px;
  display: block;
  border-radius: 6px;
  background: #120A06;
}

.tray-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
}

.tray-tag {
  font-size: 10px;
  color: #D7C19A;
}

.tray-hint {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  color: #C7AE82;
  letter-spacing: 0.06em;
}

.replay-overlay {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 20px));
  z-index: 14;
}

.replay-card {
  padding: 10px 12px;
  border-radius: 9px;
  border: 1.5px solid #96682B;
  background: rgba(25, 15, 9, 0.92);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.replay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.replay-score {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 800;
  color: var(--ivory);
}

.tab-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #8CFFE6;
  background: #120A06;
  border: 1px solid #3A271A;
  border-radius: 5px;
  padding: 5px 8px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.replay-btns {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Bottom Bar: exact 64px height, 160ms morph between rack-mode & fret-mode */
#bottom-bar {
  flex: 0 0 64px;
  height: 64px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #23150E 0%, #140B07 100%);
  border-top: 1px solid #4A311C;
  z-index: 20;
  touch-action: none;
}

.bar-panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  transition: transform 160ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 160ms ease;
}

#bottom-bar.rack-mode .rack-panel {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

#bottom-bar.rack-mode .fret-panel {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

#bottom-bar.fret-mode .rack-panel {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

#bottom-bar.fret-mode .fret-panel {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.spool-slots {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.spool-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 7px;
  border: 1.5px solid #4E341D;
  background: #1A100B;
  color: var(--ivory);
  padding: 2px 4px;
  cursor: pointer;
  min-width: 0;
}

.spool-slot.selected {
  border-color: var(--brass-hi);
  background: #2C1D11;
}

.spool-title {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}

.spool-tag {
  font-size: 9px;
  color: #C7AE82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.drop-lever {
  flex: 0 0 82px;
  height: 100%;
  border-radius: 8px;
  border: 1.5px solid #FFE28A;
  background: linear-gradient(180deg, #F5C451 0%, #B87B24 100%);
  color: #1A100B;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.drop-lever:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  border-color: #6E4A16;
  background: #2E1F14;
  color: #8A7355;
}

.fret-tabs {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.fret-tab {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  border-radius: 7px;
  border: 1.5px solid #5C3D22;
  background: #1B110B;
  color: var(--ivory);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.fret-tab:active {
  transform: scale(0.95);
}

.fret-tab.grace {
  border-color: #FFF4D6;
  background: #3A2715;
}

.fret-tab.snapped {
  opacity: 0.35;
}

.fret-note {
  font-size: 13px;
  font-weight: 800;
}

.fret-key {
  font-size: 9px;
  color: #C7AE82;
}

.chord-pips {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cpip {
  width: 20px;
  height: 26px;
  border-radius: 4px;
  border: 1px solid #5C3D22;
  background: #120A06;
  color: #7A6345;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cpip.lit {
  border-color: #FFE28A;
  background: #4B3212;
  color: #FFE28A;
}

.cpip.surge {
  border-color: #FFF4D6;
  background: #F5C451;
  color: #1A100B;
}

/* Thumbnail mode hides chrome */
body.thumb-mode #top-bezel,
body.thumb-mode #bottom-bar,
body.thumb-mode .overlay-actions,
body.thumb-mode .banner {
  display: none !important;
}
