/* ==========================================================================
   Palette & type — a warm "archive / heritage" theme.
   Layout structure is unchanged; only colour, type and spacing are tuned.
   ========================================================================== */

:root {
  --bg: #ece3d4;
  --paper: #fffdf8;
  --ink: #262a2f;
  --muted: #6d7278;
  --faint: #9aa0a6;
  --line: #e6dcc9;
  --brand: #7c2d12;      /* deep terracotta  */
  --brand-2: #b45309;    /* amber accent     */
  --navy: #23364f;       /* deep slate blue  */
  --navy-dark: #182739;
  --ok: #0f766e;         /* teal — completed */
  --ok-bg: #f0fdfa;
  --ok-line: #99f6e4;
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', 'Songti SC', serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% 0%, rgba(180, 83, 9, 0.06), transparent 42%),
    radial-gradient(circle at 92% 4%, rgba(35, 54, 79, 0.06), transparent 40%);
  padding: 24px 20px 40px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
}

h1 {
  font-family: var(--serif);
  font-size: 1.55rem;
  line-height: 1.2;
  color: #1e2a38;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 14px;
}

h3 {
  font-family: var(--serif);
  font-size: 0.98rem;
  font-weight: 700;
  color: #33383d;
  margin-bottom: 8px;
}

p {
  color: #5d6369;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
}

/* Header */

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 0 4px;
}

.hub-url {
  font-size: 0.8rem;
  margin-top: 4px;
}

.app-tagline {
  font-size: 0.86rem;
  color: #6a6155;
  margin-top: 6px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-badge {
  display: none;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  background: #94a3b8;
}

.role-badge.teacher { background: var(--navy); }
.role-badge.student { background: var(--brand); }
.role-badge.guest { background: #8a8073; }

.conn-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5a5347;
  background: #e4dbc9;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.conn-badge[data-state="connecting"] { color: #92400e; background: #fef3c7; }
.conn-badge[data-state="connected"] { color: #065f46; background: #d1fae5; }
.conn-badge[data-state="closed"] { color: #991b1b; background: #fee2e2; }

/* Panels */

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(76, 60, 34, 0.06), 0 8px 24px -18px rgba(76, 60, 34, 0.35);
  padding: 22px 24px;
  margin-bottom: 16px;
}

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

.panel-head h2 {
  margin-bottom: 0;
}

/* Intro card */

.intro-card {
  background: linear-gradient(180deg, #fffdf8 0%, #fdf6ea 100%);
  border-left: 4px solid var(--brand-2);
}

.intro-lead {
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.6;
  color: #4a4238;
  margin-bottom: 18px;
}

.intro-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.intro-col {
  padding-top: 4px;
}

.tip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.tip-list li {
  position: relative;
  padding-left: 22px;
  font-size: 0.85rem;
  color: #55504a;
}

.tip-list li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.52em;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--brand-2);
  transform: rotate(45deg);
}

.tip-list strong {
  color: var(--brand);
  font-weight: 700;
}

/* Forms */

.params {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

input,
select,
textarea {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink);
  padding: 8px 11px;
  border: 1px solid #d6ccb9;
  border-radius: 8px;
  background: #fff;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.16);
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.params .form-actions {
  grid-column: 1 / -1;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border: 1px solid #d6ccb9;
  border-radius: 8px;
  background: #fff;
  color: #3d434a;
  cursor: pointer;
}

.btn:hover { background: #f6f0e6; }

.btn.primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.btn.primary:hover { background: var(--navy-dark); }

.btn.small {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* Network test steps */

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.step {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
  background: #faf6ee;
}

.step .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cdc3b1;
}

.step.skip {
  display: none;
}

.step.busy {
  border-color: #fcd34d;
  color: #92400e;
  background: #fffbeb;
}

.step.busy .dot {
  background: #f59e0b;
  animation: pulse 1s ease-in-out infinite;
}

.step.ok {
  border-color: var(--ok-line);
  color: #065f46;
  background: var(--ok-bg);
}

.step.ok .dot { background: var(--ok); }

.step.err {
  border-color: #fecaca;
  color: #991b1b;
  background: #fef2f2;
}

.step.err .dot { background: #ef4444; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.ping-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ping-result {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  color: #5a5347;
}

/* Identity card */

.identity-card {
  display: none;
}

.identity-card dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.identity-card dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
}

.identity-card dd {
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

/* Message log */

.log-wrap {
  margin-top: 12px;
  max-height: 340px;
  overflow-y: auto;
  background: #201b14;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.6;
}

.log-row {
  display: flex;
  gap: 10px;
  padding: 1px 0;
}

.log-ts {
  flex: none;
  color: #8a7f6b;
}

.log-dir {
  flex: none;
  width: 1em;
  text-align: center;
}

.log-dir.in { color: #7dd3fc; }
.log-dir.out { color: #fbbf24; }
.log-dir.err { color: #f87171; }
.log-dir.info { color: #a99e89; }

.log-body {
  color: #efe6d6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.log-row:has(.log-dir.err) .log-body { color: #fca5a5; }

/* Composer */

.composer-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.composer-row label {
  flex: 1 1 180px;
}

.payload-label {
  margin-top: 14px;
}

textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}

.composer .form-actions {
  margin-top: 12px;
}

/* Error screen */

.error-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(30, 26, 20, 0.92);
}

.error-box {
  max-width: 640px;
  width: 100%;
  background: #2a241c;
  color: #efe6d6;
  border-radius: 12px;
  padding: 28px 32px;
}

.error-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #7f1d1d;
  color: #fecaca;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-bottom: 14px;
}

.error-box h2 {
  font-size: 1.1rem;
  text-transform: none;
  letter-spacing: 0;
  color: #fecaca;
  margin-bottom: 8px;
}

.error-box p {
  color: #d8cdb9;
  font-size: 0.9rem;
}

#err-detail {
  display: none;
  margin-top: 14px;
  padding: 12px;
  max-height: 260px;
  overflow: auto;
  background: #201b14;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #efe6d6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.error-box .btn {
  margin-top: 18px;
  background: #4a3f31;
  border-color: #4a3f31;
  color: #fff;
}

.error-box .btn:hover {
  background: #5c4f3f;
}

/* Chatbot */

.chat-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-status {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.chat-wrap {
  margin-top: 12px;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px;
}

.chat-empty {
  color: var(--faint);
  font-size: 0.85rem;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.assistant {
  align-self: flex-start;
}

.msg-who {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
}

.msg-body {
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 0.88rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user .msg-body {
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.msg.assistant .msg-body {
  background: #f4ede0;
  color: var(--ink);
  border: 1px solid #ece1cd;
  border-bottom-left-radius: 3px;
}

.msg.error .msg-body {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.msg.streaming .msg-body::after {
  content: '▋';
  margin-left: 2px;
  animation: pulse 1s steps(2) infinite;
}

.system-wrap {
  margin-top: 14px;
}

.chat-composer {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  align-items: flex-end;
}

.chat-composer textarea {
  flex: 1;
}

.chat-hint {
  font-size: 0.72rem;
  color: var(--faint);
  margin-top: 6px;
}

@media (max-width: 640px) {
  body { padding: 14px; }
  .params { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .intro-grid { grid-template-columns: 1fr; gap: 16px; }
}

/* Tutor app */

.tutor-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
  gap: 16px;
  align-items: start;
}

.objective-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.objective {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.objective-box {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #cdc3b1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
}

.objective strong {
  display: block;
  font-size: 0.88rem;
  color: var(--ink);
}

.objective p {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: #5d6369;
}

.objective.done {
  border-color: var(--ok-line);
  background: var(--ok-bg);
}

.objective.done .objective-box {
  background: var(--ok);
  border-color: var(--ok);
}

.student-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.student-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.student-row:hover {
  background: #faf6ee;
  border-color: #d6ccb9;
}

.student-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.student-progress {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.student-progress.complete {
  color: var(--ok);
}

.student-meta {
  font-size: 0.75rem;
  color: var(--faint);
}

.transcript-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  .tutor-layout { grid-template-columns: 1fr; }
}
