:root {
  --bg: #121212;
  --bg-panel: #1a1a1a;
  --border: #2c2c2c;
  --gold: #c9a24b;
  --gold-soft: #8a7238;
  --text: #ece7de;
  --muted: #9a938a;
  --danger: #c0564f;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
}

body { font-family: -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif; }

h1, h2, h3 { font-family: Georgia, 'Times New Roman', serif; letter-spacing: 0.02em; }

.screen { height: 100vh; width: 100%; }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* --- Login --- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
}

.login-card h1 {
  color: var(--gold);
  margin: 0 0 4px;
  font-size: 1.8rem;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
  text-align: left;
}

.login-card label { font-size: 0.85rem; color: var(--muted); }

input, textarea {
  background: #0e0e0e;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  width: 100%;
}

button {
  background: var(--gold);
  color: #141414;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

button:active { background: var(--gold-soft); }

.icon-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.error { color: var(--danger); font-size: 0.85rem; }
.status { font-size: 0.85rem; color: var(--gold); }

/* --- App shell --- */
#app-screen {
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.app-title strong { color: var(--gold); margin-right: 8px; }

.view {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px calc(70px + var(--safe-bottom));
}

#view-model { display: flex; flex-direction: column; padding: 0; position: relative; }

#viewer-wrap {
  position: relative;
  flex: 1;
  min-height: 300px;
  background: #000;
}

#viewer-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: rgba(0,0,0,0.5);
}

.viewer-hint {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}

.layers-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.badge-concept {
  font-size: 0.65rem;
  background: var(--danger);
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: 0.04em;
}

/* --- Element panel (bottom sheet on mobile) --- */
.element-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  background: var(--bg-panel);
  border-top: 1px solid var(--gold-soft);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(14px + var(--safe-bottom));
  overflow-y: auto;
  z-index: 20;
}

.element-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.element-props { margin: 10px 0; font-size: 0.85rem; }
.element-props dt { color: var(--muted); margin-top: 6px; }
.element-props dd { margin: 0 0 4px; }

.upload-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.media-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0e0e0e;
}

.media-item img, .media-item video { width: 100%; height: 90px; object-fit: cover; display: block; }
.media-item .caption { font-size: 0.7rem; padding: 4px 6px; color: var(--muted); }

.journal-list { list-style: none; padding: 0; margin: 0; }
.journal-list li {
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  font-size: 0.85rem;
}
.journal-list .ts { color: var(--muted); font-size: 0.75rem; display: block; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}

.nav-btn {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 0;
  padding: 12px 4px;
  font-size: 0.8rem;
}

.nav-btn.active { color: var(--gold); font-weight: 700; }

/* --- Desktop layout --- */
@media (min-width: 900px) {
  #view-model { flex-direction: row; }
  #viewer-wrap { order: 1; }
  .layers-bar { order: 2; flex-direction: column; border: none; border-left: 1px solid var(--border); width: 220px; }
  .element-panel {
    position: static;
    width: 320px;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--gold-soft);
    border-top: none;
  }
  .bottom-nav { position: static; max-width: 300px; margin: 0 auto 10px; border-radius: 10px; overflow: hidden; }
}
