:root {
  --bg: #0a0a0b;
  --surface: #131316;
  --text: #e8e8e8;
  --muted: #8a8a94;

  --white: #e8e8e8;
  --red: #e04b4b;
  --black: #8a8a94;
  --yellow: #e0a83a;
  --green: #4ba85f;
  --blue: #4b7fe0;

  --serif: "Fraunces", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  padding: 2rem 1.5rem 4rem;
}

header { text-align: center; margin-bottom: 1.75rem; }
h1 {
  font-size: 2.4rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin: 0;
}
.tagline { color: var(--muted); font-size: 1rem; margin: 0.35rem 0 0; }

/* --- input ---------------------------------------------------------------- */
#problem-form {
  max-width: 720px;
  margin: 0 auto 2.5rem;
}
textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid #26262b;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.5;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--blue); }

.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
button {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.6rem 1.3rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
#submit { background: var(--blue); color: #fff; }
#submit:disabled { opacity: 0.4; cursor: not-allowed; }
.ghost { background: transparent; color: var(--muted); border-color: #26262b; }
.ghost:hover { color: var(--text); }
.timer {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--blue);
  margin-left: auto;
}

/* --- hexagon grid --------------------------------------------------------- */
.hex {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, minmax(150px, auto));
  gap: 1.25rem;
}
.connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.pos-tl { grid-area: 1 / 1; }
.pos-tr { grid-area: 1 / 3; }
.pos-l  { grid-area: 2 / 1; }
.center { grid-area: 2 / 2; }
.pos-r  { grid-area: 2 / 3; }
.pos-bl { grid-area: 3 / 2; }

/* --- panels --------------------------------------------------------------- */
.panel {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid;
  border-color: color-mix(in srgb, var(--accent, #333) 45%, #26262b);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  min-height: 150px;
  opacity: 0.15;
  transition: opacity 0.5s ease, box-shadow 0.6s ease, transform 0.4s ease;
}
.panel[data-hat="white"]  { --accent: var(--white); }
.panel[data-hat="red"]    { --accent: var(--red); }
.panel[data-hat="black"]  { --accent: var(--black); }
.panel[data-hat="yellow"] { --accent: var(--yellow); }
.panel[data-hat="green"]  { --accent: var(--green); }
.panel[data-hat="blue"]   { --accent: var(--blue); }

.panel .label {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.7rem;
}
.panel .body {
  font-size: 1.02rem;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--text);
}
.center { min-height: 180px; }
.center .body { font-size: 1.06rem; }

/* pulsing while empty */
.panel.pending {
  opacity: 0.15;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.1; }
  50% { opacity: 0.24; }
}

/* the arrival moment: full opacity + a brief color bloom that settles */
.panel.active {
  opacity: 1;
  animation: bloom 1.1s ease-out;
}
@keyframes bloom {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent);
    transform: scale(0.985);
  }
  40% {
    box-shadow: 0 0 34px 4px color-mix(in srgb, var(--accent) 45%, transparent);
    transform: scale(1);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}
.panel.done { opacity: 1; }

/* streaming caret */
.body .caret {
  display: inline-block;
  width: 0.5ch;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* retry button on a failed hat */
.retry {
  margin-top: 0.6rem;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.error-text { color: var(--red); font-style: italic; }

/* --- login gate ----------------------------------------------------------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 10, 11, 0.92);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* The `hidden` attribute must win over `display:flex` above, or the gate never
   closes after a successful login. */
.gate[hidden] {
  display: none;
}
.gate-card {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: min(360px, 90vw);
  background: var(--surface);
  border: 1px solid #26262b;
  border-radius: 14px;
  padding: 2rem 1.75rem;
}
.gate-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
}
.gate-tag { color: var(--muted); margin: 0; font-size: 0.98rem; }
.gate-card input {
  background: #0e0e10;
  color: var(--text);
  border: 1px solid #26262b;
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  font-family: var(--serif);
  font-size: 1rem;
}
.gate-card input:focus { outline: none; border-color: var(--blue); }
.gate-card button {
  background: var(--blue);
  color: #fff;
  border: none;
}
.gate-error { color: var(--red); font-size: 0.9rem; }

/* --- responsive: single column, ordered by CSS ---------------------------- */
@media (max-width: 768px) {
  .hex {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .connectors { display: none; }
  .panel { grid-area: auto !important; }
  .pos-tl { order: 1; } /* White */
  .pos-tr { order: 2; } /* Red */
  .pos-l  { order: 3; } /* Black */
  .pos-r  { order: 4; } /* Yellow */
  .pos-bl { order: 5; } /* Green */
  .center { order: 6; } /* Blue */
}
