[data-theme="light"] {
  --wall1: #a8c0ff; --wall2: #e0b3ff;
  --bar: rgba(255,255,255,0.55); --bar-text: #1d1d1f;
  --win-bg: rgba(255,255,255,0.92); --title-bg: #e9e9eb; --menu-bg: rgba(246,246,248,0.97);
  --text: #1d1d1f; --muted: #6e6e73; --accent: #0a60d6;
  --prompt: #1a8f3c; --cmd: #b4326e; --border: rgba(0,0,0,0.15);
}

[data-theme="dark"] {
  --wall1: #1b2735; --wall2: #4b3a6b;
  --bar: rgba(30,30,30,0.55); --bar-text: #f5f5f7;
  --win-bg: rgba(28,28,30,0.94); --title-bg: #2d2d2f; --menu-bg: rgba(44,44,46,0.97);
  --text: #e5e5ea; --muted: #98989d; --accent: #64a8ff;
  --prompt: #5fd77a; --cmd: #ff8fc0; --border: rgba(255,255,255,0.15);
}

[data-theme="dracula"] {
  --wall1: #282a36; --wall2: #44475a;
  --bar: rgba(40,42,54,0.6); --bar-text: #f8f8f2;
  --win-bg: rgba(40,42,54,0.96); --title-bg: #343746; --menu-bg: rgba(52,55,70,0.98);
  --text: #f8f8f2; --muted: #8b93b8; --accent: #8be9fd;
  --prompt: #50fa7b; --cmd: #ff79c6; --border: rgba(255,255,255,0.15);
}

[data-theme="solarized"] {
  --wall1: #fdf6e3; --wall2: #93a1a1;
  --bar: rgba(238,232,213,0.7); --bar-text: #073642;
  --win-bg: rgba(253,246,227,0.95); --title-bg: #eee8d5; --menu-bg: rgba(238,232,213,0.98);
  --text: #586e75; --muted: #93a1a1; --accent: #268bd2;
  --prompt: #859900; --cmd: #d33682; --border: rgba(0,0,0,0.15);
}

[data-theme="nord"] {
  --wall1: #2e3440; --wall2: #5e81ac;
  --bar: rgba(46,52,64,0.6); --bar-text: #eceff4;
  --win-bg: rgba(46,52,64,0.95); --title-bg: #3b4252; --menu-bg: rgba(59,66,82,0.98);
  --text: #d8dee9; --muted: #8f9bb3; --accent: #88c0d0;
  --prompt: #a3be8c; --cmd: #b48ead; --border: rgba(255,255,255,0.15);
}

[data-theme="matrix"] {
  --wall1: #000000; --wall2: #003b12;
  --bar: rgba(0,0,0,0.7); --bar-text: #33ff66;
  --win-bg: rgba(0,12,0,0.96); --title-bg: #031a08; --menu-bg: rgba(3,26,8,0.98);
  --text: #33ff66; --muted: #1f9c40; --accent: #7dffa0;
  --prompt: #33ff66; --cmd: #b6ffc8; --border: rgba(51,255,102,0.3);
}

* { box-sizing: border-box; }
:root { --apple: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 814 1000'%3E%3Cpath d='M788 341c-6 5-109 62-109 190 0 148 130 200 134 201-1 3-21 71-69 141-43 61-88 123-156 123s-86-40-165-40c-77 0-104 41-167 41s-106-57-156-127C46 765 0 637 0 516c0-195 127-298 252-298 66 0 121 43 163 43 40 0 102-46 177-46 29 0 131 3 196 124zM554 160c31-37 53-89 53-141 0-7-1-15-2-20-50 2-110 33-146 75-28 32-55 85-55 138 0 8 1 16 2 19 3 1 8 1 13 1 45 0 102-30 135-72z'/%3E%3C/svg%3E"); }

html, body { margin: 0; overflow: hidden; }

body {
  height: 100dvh; /* dvh: excludes the mobile browser address bar */
  font-family: "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: var(--fs, 14px);
  color: var(--text);
  background: linear-gradient(135deg, var(--wall1), var(--wall2));
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Menu bar */
#menubar {
  position: relative; z-index: 10; flex: none;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 26px;
  padding: 0 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  font-size: 13px;
  color: var(--bar-text);
  background: var(--bar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
#menubar .spacer { flex: 1; }
#menus { display: flex; height: 100%; }
.menu { position: relative; display: flex; align-items: center; padding: 0 9px; border-radius: 4px; cursor: default; user-select: none; }
.menu.bold { font-weight: 600; }
.menu.open { background: var(--accent); color: #fff; }
.apple::before { content: ""; display: block; width: 13px; height: 15px; background: currentColor; -webkit-mask: var(--apple) center / contain no-repeat; mask: var(--apple) center / contain no-repeat; }
.dropdown {
  position: absolute; top: 26px; left: 0; min-width: 230px; padding: 5px;
  background: var(--menu-bg); color: var(--text); font-weight: 400;
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.dropdown .item { display: flex; justify-content: space-between; gap: 24px; padding: 3px 10px; border-radius: 4px; white-space: nowrap; }
.dropdown .item:hover { background: var(--accent); color: #fff; }
.dropdown .item .check { width: 14px; }
.dropdown .item .keys { opacity: 0.6; }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 4px 6px; }
@media (max-width: 600px) {
  #menubar { gap: 8px; padding: 0 6px; }
  .menu { position: static; padding: 0 7px; }
  .dropdown { left: 8px; right: 8px; min-width: 0; }
  .dropdown .item { padding: 9px 10px; }
  #clock { display: none; }
  .dropdown .keys { display: none; }
}

/* Terminal window */
#window {
  position: absolute;
  width: 900px; height: 600px;
  min-width: 320px; min-height: 200px;
  max-width: 100vw;
  resize: both;
  display: flex;
  flex-direction: column;
  background: var(--win-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.25s ease-out;
  transition: opacity 0.2s, transform 0.2s;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96); } }
#window.hidden { opacity: 0; transform: scale(0.92); pointer-events: none; }
#window.anim { transition: left 0.25s, top 0.25s, width 0.25s, height 0.25s, border-radius 0.25s; }

/* Maximised (and always on phones): fill everything below the menu bar. !important beats the inline left/top/size set by dragging. */
#window.max { left: 0 !important; top: 26px !important; width: 100% !important; height: calc(100% - 26px) !important; border-radius: 0; border: 0; resize: none; }

#titlebar {
  cursor: grab; user-select: none; touch-action: none;
  position: relative;
  padding: 10px 14px;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  color: var(--muted);
  background: var(--title-bg);
  border-bottom: 1px solid var(--border);
}
.dots { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: flex; gap: 8px; }
.dot { position: relative; width: 12px; height: 12px; border-radius: 50%; cursor: pointer; box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.25); }
.dot:active { filter: brightness(0.8); }
/* macOS shows glyphs on all three buttons while the pointer is over the group */
.dot::after { content: ""; position: absolute; inset: 0; opacity: 0; background-position: center; background-repeat: no-repeat; background-size: 8px; transition: opacity 0.1s; }
.dots:hover .dot::after { opacity: 1; }
.dot.red::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1.5 1.5l5 5m0-5l-5 5' stroke='%234d0000' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.dot.yellow::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1.2 4h5.6' stroke='%235a3a00' stroke-width='1.2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.dot.green::after { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath d='M1.2 1.2h3.6L1.2 4.8zM6.8 6.8H3.2l3.6-3.6z' fill='%23003d0a'/%3E%3C/svg%3E"); }
.red { background: #ff5f57; } .yellow { background: #febc2e; } .green { background: #28c840; }

#screen { flex: 1; padding: 14px 16px; overflow-y: auto; line-height: 1.5; }
#output > div { white-space: pre-wrap; overflow-wrap: anywhere; }
#output .banner { white-space: pre; overflow-x: auto; color: var(--accent); font-size: 11px; line-height: 1.15; }

/* Prompt line. The real input sits invisibly on top; #mirror shows what it contains. */
.line { position: relative; display: flex; gap: 8px; }
#mirror { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-all; }
#cc { box-shadow: inset 0 0 0 1px var(--text); }
.line.focused #cc { background: var(--text); color: var(--title-bg); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { background: transparent; color: inherit; } }
.prompt { color: var(--prompt); white-space: nowrap; }
#input {
  position: absolute; inset: 0; width: 100%; opacity: 0;
  border: 0; outline: 0; padding: 0;
  background: transparent;
  font: inherit; color: var(--text);
  caret-color: var(--text);
}

a { color: var(--accent); }
.cmd { color: var(--cmd); }
.cmd.run { cursor: pointer; }
.cmd.run:hover { text-decoration: underline; }
.swatch { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--border); border-radius: 4px; background: var(--title-bg); vertical-align: middle; }
.swatch i { width: 10px; height: 10px; border-radius: 2px; }
.swatch i:nth-child(1) { background: var(--prompt); }
.swatch i:nth-child(2) { background: var(--cmd); }
.swatch i:nth-child(3) { background: var(--accent); }
#hint { display: none; position: absolute; top: 50%; left: 0; right: 0; text-align: center; color: var(--bar-text); opacity: 0.6; font-family: -apple-system, sans-serif; }
body.closed #hint { display: block; }
.muted { color: var(--muted); }
table { border-collapse: collapse; }
td { padding: 1px 24px 1px 0; vertical-align: top; }
td:first-child { white-space: nowrap; }

@media (max-width: 600px) {
  #window { left: 0 !important; top: 26px !important; width: 100% !important; height: calc(100% - 26px) !important; border-radius: 0; border: 0; resize: none; }
  #titlebar { cursor: default; }
  #input { font-size: 16px; } /* 16px stops iOS zooming the page on focus */
  #output .banner { font-size: 2vw; }
  #screen { padding: 12px; -webkit-overflow-scrolling: touch; }
}
