:root {
  --bg: #0e0c0a;
  --surface: #161310;
  --panel: #1a1714;
  --border: #3a2e22;
  --border-light: #4a3d2e;
  --gold: #c9a84c;
  --gold-dim: #8a6e32;
  --gold-bright: #e8c96a;
  --crimson: #8b1a1a;
  --crimson-bright: #c0392b;
  --text: #d4c4a8;
  --text-dim: #7a6a54;
  --text-bright: #ede0c4;
  --highlight-bg: #5a3a00;
  --highlight-text: #ffd97a;
  --success: #2d6a2d;
  --success-bright: #4caf50;
  --code-bg: #120f0c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "IM Fell English", Georgia, serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  position: relative;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(139, 26, 26, 0.08) 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(201, 168, 76, 0.04) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  position: relative;
  z-index: 5;
}

.app-header {
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20, 15, 10, 0.96) 0%, rgba(16, 12, 9, 0.88) 100%);
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.app-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-header h1 {
  margin: 0 0 0.25rem;
  font-family: "Cinzel", serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.15em;
  text-shadow: 0 0 30px rgba(201, 168, 76, 0.3);
}

.subtitle {
  margin: 0;
  font-family: "IM Fell English", serif;
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.9rem;
  max-width: 34rem;
}

.beta-pill {
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  background: radial-gradient(circle at top, rgba(201, 168, 76, 0.22), rgba(16, 12, 9, 0.95));
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-bright);
}

.challenge-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.challenge-steps {
  display: flex;
  gap: 0.25rem;
}

.challenge-step-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.85);
  background: rgba(15, 23, 42, 0.7);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.8);
  opacity: 0.7;
}

.challenge-step-dot.current {
  background: radial-gradient(circle at top, #38bdf8, #2563eb);
  border-color: rgba(191, 219, 254, 0.95);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.9),
    0 0 0 4px rgba(37, 99, 235, 0.4);
  opacity: 1;
}

.challenge-step-dot.completed {
  background: linear-gradient(to bottom right, #4ade80, #16a34a);
  border-color: rgba(190, 242, 100, 0.9);
  opacity: 0.95;
}

#challenge-counter {
  font-weight: 600;
  color: var(--text-bright);
  font-family: "Cinzel", serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr);
  gap: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--border);
}

.panel {
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-family: "Cinzel", serif;
  color: var(--text-dim);
}

.text-panel {
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.play-text {
  margin: 0;
  padding: 0;
  white-space: pre-wrap;
  font-family: "IM Fell English", Georgia, serif;
  font-size: 0.82rem;
  line-height: 1.8;
  flex: 1;
}

.line {
  display: flex;
  gap: 0.5rem;
}

.line-number {
  width: 3rem;
  flex-shrink: 0;
  color: var(--text-dim);
  text-align: right;
  padding-right: 0.5rem;
  user-select: none;
  font-family: "Fira Code", monospace;
  font-size: 0.7rem;
}

.line-text {
  flex: 1;
}

.line.highlight {
  background: linear-gradient(to right, rgba(90, 58, 0, 0.55), transparent);
}

.line mark {
  background: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 0 1px;
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(255, 180, 0, 0.2);
}

.right-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 0.6rem;
  padding: 16px 18px 16px 18px;
  background: var(--surface);
}

.challenge-panel,
.regex-panel,
.reference-panel,
.results-panel {
  background: var(--panel);
  border-radius: 4px;
  padding: 0.65rem 0.7rem 0.75rem;
  border: 1px solid var(--border);
}

.challenge-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.challenge-tag {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold-dim);
  background: var(--code-bg);
  border-radius: 3px;
  border: 1px solid var(--border-light);
  padding: 0.12rem 0.55rem;
}

.challenge-panel h3 {
  margin: 0.25rem 0;
  font-size: 1rem;
  font-family: "Cinzel", serif;
  color: var(--text-bright);
}

.challenge-description {
  margin: 0.1rem 0 0.25rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  font-style: italic;
}

.challenge-extra {
  margin-top: 0.1rem;
  font-size: 0.8rem;
  color: var(--gold-dim);
  font-family: "Fira Code", monospace;
  background: var(--code-bg);
  border-radius: 3px;
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.challenge-feedback {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  min-height: 1.1rem;
}

.challenge-feedback.success {
  color: var(--success-bright);
}

.challenge-feedback.error {
  color: var(--crimson-bright);
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.regex-input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border-light);
  background: var(--code-bg);
  color: #e8d5a3;
  font-family: "Fira Code", monospace;
  font-size: 0.85rem;
}

.regex-input:focus {
  outline: none;
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.1);
}

.primary-button,
.secondary-button {
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.primary-button {
  background: var(--gold);
  color: var(--bg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
  font-family: "Cinzel", serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.primary-button:disabled {
  opacity: 0.55;
  cursor: default;
  box-shadow: none;
}

.secondary-button {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border-light);
  font-family: "Cinzel", serif;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.run-button {
  margin-top: 0.35rem;
}

.regex-error {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  min-height: 1rem;
  color: var(--crimson-bright);
  font-family: "Fira Code", monospace;
}

.reference-list {
  list-style: disc;
  margin: 0.1rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.reference-list code {
  background: var(--code-bg);
  padding: 0 0.15rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border);
}

.results-summary {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.results-list {
  max-height: 11.5rem;
  overflow: auto;
  border-radius: 0.4rem;
  background: var(--panel);
  border: 1px solid var(--border);
}

.result-item {
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(58, 46, 34, 0.5);
}

.result-item:last-child {
  border-bottom: none;
}

.result-item-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--text-dim);
  margin-bottom: 0.1rem;
}

.result-line-number {
  font-weight: 500;
}

.result-preview {
  color: var(--text);
}

.status-message {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.app-footer {
  padding: 0.5rem 1.5rem 0.8rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: linear-gradient(to top, rgba(16, 12, 9, 0.96), rgba(16, 12, 9, 0.88));
}

code {
  font-family: "Fira Code", monospace;
  font-size: 0.78rem;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.2fr) minmax(0, 1.6fr);
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .challenge-status {
    align-self: stretch;
    justify-content: space-between;
  }
}

