/* ==========================================================================
   REV-01 FIELD RECORDER (Tactile Physical Hardware Theme)
   Inspired by Teenage Engineering & Dieter Rams Functionalism
   Zero AI generic tropes: No purple glow, no frosted cards, no fake badges
   ========================================================================== */

:root {
  --chassis-bg: #16171b;
  --chassis-border: #262830;
  --bezel-bg: #0d0e11;
  
  --lcd-bg: #090a0c;
  --lcd-grid: rgba(255, 255, 255, 0.02);
  --lcd-text: #e2e8f0;
  --lcd-dim: #475569;
  --lcd-accent: #00ffaa;
  
  --key-dark: #22242c;
  --key-dark-pressed: #1a1b22;
  --key-dark-edge: #111217;
  
  --key-rec: #ff3838;
  --key-rec-active: #d63031;
  --key-rec-edge: #991a1a;
  
  --key-reverse: #0984e3;
  --key-reverse-edge: #06528d;
  
  --font-tech: "SF Mono", "Roboto Mono", Menlo, Consolas, Monaco, monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100%;
  background-color: #0b0c0e;
  color: var(--lcd-text);
  font-family: var(--font-ui);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: env(safe-area-inset-top, 12px) 12px env(safe-area-inset-bottom, 12px);
  touch-action: pan-y;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Hardware Chassis Shell */
.device-chassis {
  width: 100%;
  max-width: 480px;
  background: var(--chassis-bg);
  border: 1px solid var(--chassis-border);
  border-radius: 24px;
  padding: 18px;
  box-shadow: 
    0 24px 60px rgba(0, 0, 0, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -2px 4px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 16px;
  user-select: none;
}

/* Header */
.hardware-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.device-branding {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-model {
  font-family: var(--font-tech);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: #ffffff;
}

.brand-tag {
  font-family: var(--font-tech);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: #64748b;
  font-weight: 600;
}

.hardware-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator-offline {
  font-family: var(--font-tech);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--lcd-accent);
  background: rgba(0, 255, 170, 0.08);
  border: 1px solid rgba(0, 255, 170, 0.25);
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.hw-mini-btn {
  background: #252834;
  border: 1px solid #363a4a;
  color: #94a3b8;
  font-family: var(--font-tech);
  font-weight: bold;
  font-size: 0.8rem;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.hw-mini-btn:active {
  transform: translateY(1px);
}

/* Bezel & LCD Screen */
.screen-housing {
  background: var(--bezel-bg);
  border: 1px solid #1f222a;
  border-radius: 14px;
  padding: 10px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.9);
}

.screen-bezel {
  background: var(--lcd-bg);
  border: 1px solid #1a1d24;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.screen-meta-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lcd-text {
  font-family: var(--font-tech);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  font-weight: 700;
  color: #94a3b8;
}

#modeDisplay.recording {
  color: var(--key-rec);
}

#modeDisplay.reversing {
  color: #38bdf8;
}

#modeDisplay.playing {
  color: var(--lcd-accent);
}

/* Canvas Viewport */
.canvas-viewport {
  position: relative;
  width: 100%;
  height: 100px;
  background: #050607;
  border-radius: 4px;
  border: 1px solid #14161c;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tapeCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.screen-empty-hint {
  position: absolute;
  font-family: var(--font-tech);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: #334155;
  font-weight: 700;
  pointer-events: none;
}

/* Screen Bottom Meta */
.screen-meta-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-top: 4px;
  border-top: 1px solid #141720;
}

.counter-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.counter-label {
  font-family: var(--font-tech);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  color: var(--lcd-dim);
}

.counter-digits {
  font-family: var(--font-tech);
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.08em;
}

.screen-btn-toggle {
  background: transparent;
  border: 1px solid #282e3d;
  color: #64748b;
  font-family: var(--font-tech);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
}

.screen-btn-toggle.active {
  background: #00ffaa;
  color: #050607;
  border-color: #00ffaa;
}

/* ==========================================================================
   Physical Keypad Zone (Authentic Hardware Micro-Physics)
   ========================================================================== */

.keypad-zone {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 0;
}

/* General Mechanical Key Cap */
.key-hardware {
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
  position: relative;
  transition: transform 0.08s ease;
}

.key-cap {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  box-shadow: 
    0 4px 0 var(--key-dark-edge),
    0 8px 16px rgba(0, 0, 0, 0.45);
  transition: all 0.08s ease;
}

.key-hardware:active:not(:disabled) .key-cap {
  transform: translateY(3px);
  box-shadow: 
    0 1px 0 var(--key-dark-edge),
    0 3px 6px rgba(0, 0, 0, 0.4);
}

.key-hardware:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Hero Record Button */
.record-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.key-record .key-cap {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff5252, var(--key-rec));
  box-shadow: 
    0 6px 0 var(--key-rec-edge),
    0 10px 24px rgba(255, 56, 56, 0.35);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.key-record:active:not(:disabled) .key-cap {
  transform: translateY(4px);
  box-shadow: 
    0 2px 0 var(--key-rec-edge),
    0 4px 10px rgba(255, 56, 56, 0.3);
}

.key-record.recording .key-cap {
  background: radial-gradient(circle at 35% 35%, #ff7675, #d63031);
  box-shadow: 
    0 2px 0 var(--key-rec-edge),
    0 0 30px rgba(255, 56, 56, 0.6);
}

.key-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
  opacity: 0.8;
}

.key-record.recording .key-led {
  animation: led-blink 0.7s infinite;
}

@keyframes led-blink {
  0%, 100% { opacity: 1; transform: scale(1.2); }
  50% { opacity: 0.2; transform: scale(0.9); }
}

.key-record .key-label {
  font-family: var(--font-tech);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: #ffffff;
}

.keypad-caption {
  font-family: var(--font-tech);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: #64748b;
  font-weight: 700;
}

/* Playback Transport Cluster */
.transport-cluster {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.key-transport .key-cap {
  padding: 18px 14px;
  flex-direction: column;
  gap: 2px;
}

/* Hero Reverse Button */
.key-reverse .key-cap {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 1px solid #38bdf8;
  box-shadow: 
    0 4px 0 #0369a1,
    0 8px 16px rgba(3, 105, 161, 0.25);
}

.key-reverse .key-icon {
  font-family: var(--font-tech);
  font-size: 1.1rem;
  color: #38bdf8;
}

.key-reverse .key-label {
  font-family: var(--font-tech);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #ffffff;
}

.key-reverse .key-sub {
  font-size: 0.7rem;
  color: #38bdf8;
  font-weight: 700;
}

.key-reverse.active-playback .key-cap {
  border-color: #ffffff;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.6);
}

/* Normal Forward Button */
.key-forward .key-cap {
  background: linear-gradient(180deg, #272a35 0%, #1a1c24 100%);
  border: 1px solid #363b4b;
  box-shadow: 
    0 4px 0 var(--key-dark-edge),
    0 8px 16px rgba(0, 0, 0, 0.35);
}

.key-forward .key-icon {
  font-family: var(--font-tech);
  font-size: 1.1rem;
  color: #94a3b8;
}

.key-forward .key-label {
  font-family: var(--font-tech);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #cbd5e1;
}

.key-forward .key-sub {
  font-size: 0.7rem;
  color: #64748b;
  font-weight: 700;
}

.key-forward.active-playback .key-cap {
  border-color: #00ffaa;
  box-shadow: 0 0 20px rgba(0, 255, 170, 0.5);
}

/* Speed Switch Strip */
.switch-strip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #0f1013;
  border: 1px solid #20222a;
  border-radius: 8px;
  padding: 8px 12px;
}

.switch-title {
  font-family: var(--font-tech);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: #64748b;
  font-weight: 700;
}

.speed-toggle-switch {
  display: flex;
  background: #191b22;
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.speed-step {
  flex: 1;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-family: var(--font-tech);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s ease;
}

.speed-step.active {
  background: #e2e8f0;
  color: #0f172a;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Utility Keys */
.utility-cluster {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.key-util .key-cap {
  background: #1d2029;
  border: 1px solid #2e3342;
  padding: 10px;
  box-shadow: 
    0 3px 0 #12141a,
    0 4px 8px rgba(0,0,0,0.3);
}

.key-util .key-label {
  font-family: var(--font-tech);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #94a3b8;
}

/* Tape Deck Drawer (History) */
.tape-deck-section {
  background: #111215;
  border: 1px solid #20232c;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tape-deck-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.deck-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.deck-icon {
  font-family: var(--font-tech);
  color: #64748b;
}

.deck-title {
  font-family: var(--font-tech);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  font-weight: 800;
  color: #cbd5e1;
}

.deck-pill {
  font-family: var(--font-tech);
  font-size: 0.65rem;
  background: #252834;
  color: #94a3b8;
  padding: 2px 6px;
  border-radius: 4px;
}

.deck-clear-btn {
  background: none;
  border: none;
  font-family: var(--font-tech);
  font-size: 0.65rem;
  color: #e17055;
  cursor: pointer;
  letter-spacing: 0.05em;
  font-weight: bold;
}

.take-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.take-list-empty {
  font-family: var(--font-tech);
  font-size: 0.72rem;
  color: #475569;
  text-align: center;
  padding: 14px 0;
  letter-spacing: 0.08em;
}

.take-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #181a21;
  border: 1px solid #262a36;
  border-radius: 6px;
  padding: 8px 10px;
}

.take-info {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  flex: 1;
}

.take-name {
  font-family: var(--font-tech);
  font-size: 0.78rem;
  font-weight: 700;
  color: #e2e8f0;
}

.take-time {
  font-family: var(--font-tech);
  font-size: 0.65rem;
  color: #64748b;
}

.take-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-take-play {
  background: #262936;
  border: 1px solid #363b4e;
  border-radius: 4px;
  color: #e2e8f0;
  font-family: var(--font-tech);
  font-size: 0.7rem;
  font-weight: bold;
  padding: 5px 8px;
  cursor: pointer;
}

.btn-take-play.reverse {
  color: #38bdf8;
  border-color: #0284c7;
}

.btn-take-del {
  background: none;
  border: none;
  color: #64748b;
  font-family: var(--font-tech);
  font-size: 0.8rem;
  padding: 4px 6px;
  cursor: pointer;
}

.btn-take-del:hover {
  color: #ff3838;
}

/* Footer */
.hardware-footer {
  text-align: center;
  font-family: var(--font-tech);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  color: #475569;
  padding: 4px 0 0;
}

/* Modal */
.hw-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 999;
}

.hw-modal.hidden {
  display: none;
}

.hw-modal-sheet {
  background: #181a22;
  border: 1px solid #303546;
  border-radius: 16px;
  max-width: 420px;
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hw-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #282d3c;
  padding-bottom: 10px;
}

.hw-modal-header h3 {
  font-family: var(--font-tech);
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  color: #ffffff;
}

.rule-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 18px;
  font-size: 0.84rem;
  line-height: 1.5;
  color: #cbd5e1;
}

.rule-list code {
  background: #0f1015;
  border: 1px solid #2a2f3f;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-tech);
  color: #38bdf8;
  font-size: 0.78rem;
}

.rule-note {
  font-size: 0.76rem;
  color: #00ffaa;
  background: rgba(0, 255, 170, 0.08);
  border: 1px solid rgba(0, 255, 170, 0.2);
  border-radius: 6px;
  padding: 8px 12px;
}
