/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1f2937;
  --border: rgba(255,255,255,0.12);
  --accent: #00e5ff;
  --accent-dim: rgba(0,229,255,0.15);
  --text: #e6edf3;
  --text-muted: #8b949e;
  --danger: #f85149;
  --success: #3fb950;
  --tube-w: 52px;
  --tube-h: 200px;
  --layer-h: calc(var(--tube-h) / 4);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== Auth Screen ===== */
.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.auth-logo p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.form-group input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  margin-top: 8px;
}

.btn-primary:active { transform: scale(0.97); }
.btn-primary:hover { filter: brightness(1.1); }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  margin-top: 10px;
}

.btn-ghost:active { transform: scale(0.97); }

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-toggle a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.error-msg {
  background: rgba(248,81,73,0.12);
  border: 1px solid rgba(248,81,73,0.3);
  border-radius: 8px;
  color: var(--danger);
  font-size: 0.85rem;
  padding: 10px 14px;
  margin-bottom: 16px;
}

/* ===== HUD Bar ===== */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.hud-level {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  min-width: 80px;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.hud-btn:active { transform: scale(0.95); }
.hud-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.hud-btn:hover:not(.disabled) { border-color: var(--accent); color: var(--accent); }

.hud-btn .icon { font-size: 1rem; }

.hud-btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}

.hud-btn-icon:active { transform: scale(0.9); }
.hud-btn-icon:hover { color: var(--text); border-color: var(--border); }

/* ===== Game Area ===== */
.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 12px;
  overflow: hidden;
  gap: 12px;
}

.tube-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: nowrap;
}

/* ===== Tube ===== */
.tube-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  gap: 6px;
  transition: transform 0.15s;
}

.tube-wrapper:active { transform: scale(0.97); }

.tube-cap {
  width: calc(var(--tube-w) + 8px);
  height: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: 4px 4px 0 0;
  border: 2px solid rgba(255,255,255,0.25);
  border-bottom: none;
}

.tube {
  width: var(--tube-w);
  height: var(--tube-h);
  border: 2px solid rgba(255,255,255,0.25);
  border-top: none;
  border-radius: 0 0 26px 26px;
  background: rgba(255,255,255,0.04);
  box-shadow: inset 0 -4px 10px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  position: relative;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.tube.selected {
  border-color: var(--accent);
  box-shadow: inset 0 -4px 10px rgba(0,0,0,0.35), 0 0 0 3px var(--accent-dim), 0 0 16px rgba(0,229,255,0.3);
}

.tube.hint-src {
  border-color: #ffd700;
  box-shadow: inset 0 -4px 10px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,215,0,0.2), 0 0 20px rgba(255,215,0,0.4);
  animation: pulse-hint 0.6s ease-in-out infinite alternate;
}

.tube.hint-dst {
  border-color: var(--success);
  box-shadow: inset 0 -4px 10px rgba(0,0,0,0.35), 0 0 0 3px rgba(63,185,80,0.2), 0 0 20px rgba(63,185,80,0.4);
  animation: pulse-hint 0.6s ease-in-out infinite alternate;
}

.tube.shake {
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pulse-hint {
  from { filter: brightness(1); }
  to { filter: brightness(1.3); }
}

/* ===== Liquid Layers ===== */
.layer {
  width: 100%;
  transition: height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  flex-shrink: 0;
}

.layer::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 35%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.18), transparent);
  pointer-events: none;
}

/* ===== Color Map ===== */
.color-red    { background: #e53935; }
.color-blue   { background: #1e88e5; }
.color-green  { background: #43a047; }
.color-yellow { background: #fdd835; }
.color-cyan   { background: #00bcd4; }
.color-purple { background: #8e24aa; }
.color-orange { background: #fb8c00; }
.color-pink   { background: #e91e8c; }
.color-teal   { background: #00897b; }
.color-gray   { background: #607d8b; }
.color-lime   { background: #9ccc65; }
.color-brown  { background: #795548; }
.color-navy   { background: #1a237e; }
.color-magenta { background: #e040fb; }
.color-olive   { background: #9e9d24; }
.color-sky     { background: #90caf9; }

/* ===== Level Complete Overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fade-in 0.3s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.complete-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  animation: pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.complete-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.complete-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.complete-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.complete-card .btn-primary {
  max-width: 200px;
  margin: 0 auto;
}

/* ===== Admin Panel ===== */
.admin-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-header h2 {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}

.admin-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s;
}
.admin-back:hover { color: var(--text); border-color: var(--accent); }

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.admin-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
}

.code-gen-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.code-gen-row input {
  width: 80px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
}

.code-gen-row .btn-primary {
  width: auto;
  padding: 10px 20px;
  margin: 0;
  flex-shrink: 0;
}

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

.code-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: monospace;
  font-size: 0.95rem;
  gap: 8px;
}

.code-item .code-val { color: var(--accent); font-weight: 600; letter-spacing: 1px; }
.code-item .code-status { font-size: 0.75rem; color: var(--text-muted); }
.code-item .code-status.used { color: var(--danger); }

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.users-table th {
  text-align: left;
  color: var(--text-muted);
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

.users-table td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  vertical-align: middle;
}

.users-table tr:last-child td { border-bottom: none; }

.btn-danger {
  background: rgba(248,81,73,0.15);
  border: 1px solid rgba(248,81,73,0.3);
  border-radius: 6px;
  color: var(--danger);
  padding: 5px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-danger:hover { background: rgba(248,81,73,0.25); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== Small screen tube sizing ===== */
@media (max-height: 700px) {
  :root {
    --tube-h: 160px;
    --tube-w: 44px;
  }
  .hud { padding: 8px 12px; }
}

@media (max-height: 580px) {
  :root {
    --tube-h: 130px;
    --tube-w: 40px;
  }
}
