:root {
  --bg: #15171c;
  --surface: #1c1f26;
  --surface-raised: #22262f;
  --line: #33384433;
  --line-solid: #333844;
  --text: #ece8e1;
  --text-dim: #9096a1;
  --accent: #e2a33d;
  --accent-dim: #a97a2d;
  --accent-soft: #e2a33d22;
  --done: #6fae7f;
  --danger: #d16b6b;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 15% 0%, #1e222b 0%, var(--bg) 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: inherit;
}

/* ---------- Top brand bar ---------- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-solid);
  position: relative;
  z-index: 30;
}

.logo a {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.2px;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 24px;
}

.nav-links a {
  text-decoration: none;
  font-size: 14px;
  color: var(--text-dim);
  transition: color .2s ease;
}

.nav-links a:hover {
  color: var(--accent);
}

/* ---------- App shell ---------- */
.app {
  display: flex;
  min-height: calc(100vh - 61px);
  position: relative;
  width: 100%;
}

/* ---------- Tool rail (Collapsible Sidebar) ---------- */
.rail {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line-solid);
  padding: 24px 12px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 20;
}

/* Collapsed State */
.rail.collapsed {
  margin-left: -230px;
}

.rail-toggle-btn {
  position: absolute;
  top: 20px;
  right: -15px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #20140a;
  border: 2px solid var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 12px;
  z-index: 25;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  transition: transform 0.3s ease, background 0.2s ease;
  padding: 0;
}

.rail-toggle-btn:hover {
  background: #f0b24d;
}

.rail.collapsed .rail-toggle-btn {
  right: -38px;
  transform: rotate(180deg);
}

.rail-label {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 12px 12px;
  letter-spacing: 0.5px;
}

.tool-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.tool-switch .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-solid);
  flex-shrink: 0;
  transition: background .15s ease;
}

.tool-switch:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.tool-switch.active {
  background: var(--accent-soft);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.tool-switch.active .dot {
  background: var(--accent);
}

/* ---------- Main panel ---------- */
.main {
  flex: 1;
  padding: 36px 40px;
  width: 100%;
  transition: padding 0.3s ease;
}

.panel {
  display: none;
  max-width: 1100px; /* Expanded for wide cinema layout */
  width: 100%;
  margin: 0 auto;
}

.panel.active {
  display: block;
}

.panel-header {
  margin-bottom: 22px;
}

.panel-header h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
}

.panel-header p {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

.instrument {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-solid);
  border-radius: 10px;
  padding: 24px;
}

.instrument .rivet-tl { top: 8px; left: 8px; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--line-solid); }
.instrument .rivet-tr { top: 8px; right: 8px; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--line-solid); }
.instrument .rivet-bl { bottom: 8px; left: 8px; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--line-solid); }
.instrument .rivet-br { bottom: 8px; right: 8px; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--line-solid); }

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 6px;
  border: 1px solid var(--line-solid);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

button {
  padding: 11px 18px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #20140a;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: filter .15s ease;
}

button:hover {
  filter: brightness(1.08);
}

/* ---------- Video Player Container ---------- */
.video-container {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
  height: 0;
  overflow: hidden;
  border-radius: 8px;
  background: #000;
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ---------- Movies Player Search & Results ---------- */
.movie-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.movie-controls input { flex: 3; }
.movie-controls select { flex: 1.2; }

.search-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 4px;
}

.movie-card {
  background: var(--surface-raised);
  border: 1px solid var(--line-solid);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.movie-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.movie-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.movie-card-title {
  font-size: 11px;
  font-weight: 600;
  padding: 6px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.tv-controls input { flex: 1; }

.movie-servers {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.server-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  margin-right: 4px;
}

.server-btn {
  padding: 6px 12px;
  font-size: 12px;
  background: var(--surface-raised);
  color: var(--text-dim);
  border: 1px solid var(--line-solid);
  border-radius: 6px;
}

.server-btn:hover {
  color: var(--text);
  border-color: var(--accent-dim);
  filter: none;
}

.server-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ---------- Calculator ---------- */
.calc-display {
  background: #0e1015;
  border: 1px solid var(--line-solid);
  border-radius: 6px;
  padding: 18px 16px;
  text-align: right;
  font-family: var(--font-display);
  font-size: 32px;
  margin-bottom: 16px;
  overflow-x: auto;
  white-space: nowrap;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}

.calc-grid button {
  background: var(--surface-raised);
  color: var(--text);
  font-weight: 500;
  padding: 16px 0;
  font-size: 16px;
}

.calc-grid button:hover {
  background: #2a2f3a;
  filter: none;
}

.calc-grid button.op { color: var(--accent); }
.calc-grid button.equals { background: var(--accent); color: #20140a; grid-row: span 2; }
.calc-grid button.zero { grid-column: span 2; }
.calc-grid button.clear { color: var(--danger); }

/* ---------- Notes ---------- */
#notesArea {
  min-height: 250px;
  resize: vertical;
  line-height: 1.6;
}

.notes-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
}

/* ---------- Responsive Adjustments ---------- */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .rail { 
    width: 100%; 
    margin-left: 0 !important; 
    display: flex; 
    overflow-x: auto; 
    gap: 6px; 
    border-right: none; 
    border-bottom: 1px solid var(--line-solid); 
    padding: 12px; 
  }
  .rail-toggle-btn { display: none; }
  .rail-label { display: none; }
  .tool-switch { white-space: nowrap; margin-bottom: 0; width: auto; }
  .main { padding: 20px 14px; }
}