/* PonsPraat — vintage teletype PWA */
:root {
  --bg-0: #1a1a1a;
  --bg-1: #2a1a1a;
  --bg-2: #3a2420;
  --paper-0: #f4ead8;
  --paper-1: #e8d5b7;
  --paper-2: #c8b898;
  --ink-0: #1a0e0a;
  --ink-1: #2a1810;
  --ink-2: #4a3020;
  --gold: #d4a23e;
  --red: #c4452e;
  --green: #6fa83e;
  --blue: #3e6fa8;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --mono: 'Courier New', 'Consolas', monospace;
  --serif: Georgia, 'Iowan Old Style', serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }

body {
  font-family: var(--mono);
  background: radial-gradient(ellipse at center, var(--bg-2), var(--bg-0));
  color: var(--paper-0);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

#smoke { position: fixed; inset: 0; pointer-events: none; z-index: 999; opacity: 0.05; }

/* ==== BARS (header/footer) ==== */
.bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; background: var(--bg-1);
  border-bottom: 2px solid var(--gold);
  font-size: 0.9rem;
  flex-shrink: 0;
}
.bar.bottom { border: none; border-top: 2px solid var(--gold); font-size: 0.75rem; color: var(--ink-2); background: var(--bg-0); }
.bar.bottom .hint { color: var(--gold); font-style: italic; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--gold); letter-spacing: 0.05em; }
.brand h1 small { font-size: 0.7rem; color: var(--ink-2); font-weight: normal; margin-left: 8px; }
.logo { font-size: 1.6rem; filter: drop-shadow(0 0 4px var(--gold)); }

.status { display: flex; align-items: center; gap: 8px; font-family: var(--mono); }
.led { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--ink-2); box-shadow: inset 0 0 4px rgba(0,0,0,0.5); }
.led.on { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
#status-text { color: var(--gold); font-weight: bold; min-width: 100px; text-align: right; }

/* ==== MAIN: papierrol ==== */
main { flex: 1; display: flex; flex-direction: column; padding: 12px; overflow: hidden; }

.paper {
  flex: 1;
  background: linear-gradient(180deg, var(--paper-0) 0%, var(--paper-1) 50%, var(--paper-2) 100%);
  color: var(--ink-0);
  position: relative;
  border: 1px solid var(--ink-2);
  border-radius: 4px;
  box-shadow: var(--shadow), inset 0 0 60px rgba(0,0,0,0.15);
  font-family: var(--mono);
  font-size: clamp(12px, 2.5vw, 18px);
  line-height: 1.4;
  overflow: hidden;
  padding: 32px 50px;
  cursor: text;
  text-shadow: 0 0 0.5px rgba(0,0,0,0.3);
}

.paper::before {
  content: '';
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(0,0,0,0.05) 27px, rgba(0,0,0,0.05) 28px);
  pointer-events: none;
  z-index: 1;
}

.paper::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at top, transparent 70%, rgba(0,0,0,0.1) 100%);
  pointer-events: none;
  z-index: 1;
}

.perforation {
  position: absolute; top: 0; bottom: 0; width: 28px;
  background: radial-gradient(circle, var(--bg-0) 2px, transparent 3px) repeat-y;
  background-size: 6px 14px;
  background-position: center;
  opacity: 0.4;
  z-index: 2;
  pointer-events: none;
}
.perforation.left { left: 8px; }
.perforation.right { right: 8px; }

.paper-curl {
  position: absolute; left: 0; right: 0; height: 18px;
  background: linear-gradient(180deg, var(--bg-1), transparent);
  z-index: 2; pointer-events: none;
}
.paper-curl.top { top: 0; }
.paper-curl.bottom { bottom: 0; transform: rotate(180deg); background: linear-gradient(180deg, var(--bg-2), transparent); }

#output {
  position: relative; z-index: 3;
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono);
  min-height: 100%;
}

.carriage {
  display: inline-block;
  background: var(--ink-0);
  color: var(--paper-0);
  animation: blinker 1s steps(1) infinite;
  font-family: var(--mono);
}
@keyframes blinker { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ==== PANEL: controls ==== */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--ink-2);
  border-radius: 6px;
  padding: 12px;
  margin-top: 8px;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.input-row, .speed-row, .mode-row, .action-row, .ciphers {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.input-row label, .speed-row label, .mode-row label { min-width: 110px; color: var(--gold); font-weight: bold; }

input[type="text"], input[type="number"] {
  flex: 1; min-width: 200px;
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 8px 12px;
  border: 1px solid var(--ink-2);
  background: var(--bg-0);
  color: var(--paper-0);
  border-radius: 4px;
}
input[type="text"]:focus, input[type="number"]:focus { outline: 2px solid var(--gold); }
input[type="range"] { width: 200px; }
#speed-lbl { min-width: 50px; color: var(--gold); font-weight: bold; }

button {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 6px 12px;
  background: var(--bg-0);
  color: var(--paper-0);
  border: 1px solid var(--ink-2);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: bold;
}
button:hover { background: var(--ink-1); border-color: var(--gold); color: var(--gold); }
button:active { transform: translateY(1px); }
button.primary { background: var(--gold); color: var(--ink-0); border-color: var(--gold); }
button.primary:hover { background: var(--paper-0); color: var(--ink-0); }
button.tele { background: linear-gradient(180deg, var(--bg-2), var(--bg-0)); border-color: var(--ink-2); }
button.mode.active { background: var(--gold); color: var(--ink-0); border-color: var(--gold); box-shadow: 0 0 8px rgba(212,162,62,0.5); }
button.hidden { display: none; }

.counters {
  display: flex; gap: 16px; font-size: 0.8rem; color: var(--ink-2);
  padding-top: 4px; border-top: 1px dashed var(--ink-2);
}
.counters b { color: var(--gold); font-weight: bold; }

.ciphers { padding: 4px 0; }
.ciphers.hidden { display: none; }
.ciphers small { color: var(--ink-2); font-style: italic; }

/* ==== Dialogs ==== */
dialog {
  background: var(--bg-1);
  color: var(--paper-0);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 24px;
  max-width: 600px;
  width: 90vw;
  font-family: var(--mono);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,0.85); backdrop-filter: blur(4px); }
dialog h2 { color: var(--gold); margin: 0 0 12px; }
dialog h3 { color: var(--paper-0); margin: 12px 0 6px; font-size: 0.95rem; }
dialog table { width: 100%; border-collapse: collapse; margin: 6px 0; }
dialog td { padding: 3px 6px; border-bottom: 1px dashed var(--ink-2); }
dialog kbd {
  background: var(--bg-0);
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--gold);
}
dialog code {
  background: var(--bg-0);
  color: var(--green);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--mono);
}
dialog ul { padding-left: 20px; }
dialog li { margin-bottom: 4px; }
#saved-list { list-style: none; padding: 0; max-height: 200px; overflow: auto; }
#saved-list li { padding: 6px; border: 1px solid var(--ink-2); border-radius: 4px; margin-bottom: 4px; cursor: pointer; }
#saved-list li:hover { background: var(--bg-2); border-color: var(--gold); }
#saved-list li .meta { font-size: 0.75rem; color: var(--ink-2); }

/* ==== Light theme ==== */
body.light { color: var(--ink-0); background: radial-gradient(ellipse at center, #f4ead8, #e8d5b7); }
body.light .bar, body.light .panel { background: var(--paper-1); color: var(--ink-0); border-color: var(--ink-1); }
body.light .paper { background: linear-gradient(180deg, #fcf3e0, #f4ead8, #e8d5b7); color: var(--ink-0); }
body.light input[type="text"], body.light input[type="number"] { background: #fff; color: var(--ink-0); border-color: var(--ink-1); }
body.light button { background: var(--paper-1); color: var(--ink-0); border-color: var(--ink-1); }
body.light button:hover { background: var(--gold); color: var(--ink-0); }
body.light .carriage { background: var(--ink-0); color: var(--paper-0); }
body.light #smoke { opacity: 0.02; }

/* ==== Mobile ==== */
@media (max-width: 600px) {
  .bar { padding: 6px 8px; }
  .brand h1 { font-size: 0.95rem; }
  .brand h1 small { display: none; }
  main { padding: 6px; }
  .paper { padding: 24px 36px; font-size: 14px; }
  .perforation { width: 20px; }
  .panel { padding: 8px; font-size: 0.8rem; }
  .input-row label, .speed-row label, .mode-row label { min-width: 80px; font-size: 0.8rem; }
  input[type="text"] { min-width: 140px; }
  button { padding: 4px 8px; font-size: 0.75rem; }
}
