:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #176b87;
  --accent-2: #5c8a3b;
  --deny: #b42318;
  --allow: #237a3b;
  --warn: #9a6700;
  --terminal: #101820;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, select, input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem;
  border-right: 1px solid var(--line);
  background: #eef3f7;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-bottom: 1.4rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand h1, .brand p, .module-head h2, .module-head p { margin: 0; }
.brand h1 { font-size: 1.05rem; }
.brand p { color: var(--muted); font-size: 0.88rem; }

.module-nav {
  display: grid;
  gap: 0.35rem;
}

.nav-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  background: transparent;
}

.nav-button.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.nav-button.done::after {
  content: "✓";
  font-weight: 800;
}

.progress-box { margin: 1.25rem 0; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.9rem; }
.progress-track { height: 10px; background: #dce6ee; border-radius: 999px; overflow: hidden; margin-top: 0.45rem; }
#progressFill { width: 0; height: 100%; background: var(--accent-2); transition: width 180ms ease; }

.ghost-button { width: 100%; background: #fff; }

main {
  padding: 1.5rem;
  max-width: 1400px;
  width: 100%;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
  padding: 1.35rem;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #ffffff, #edf6f2);
  border-radius: 8px;
}

.hero h2 { margin: 0 0 0.3rem; font-size: 2rem; letter-spacing: 0; }
.hero p { margin: 0; color: var(--muted); }
.question {
  border-left: 4px solid var(--accent);
  padding: 0.75rem 0.9rem;
  background: rgba(255,255,255,0.72);
  border-radius: 6px;
}

.teacher-panel {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border: 1px solid #efc35d;
  background: #fff7df;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.teacher-panel h3, .teacher-panel p { margin: 0; }
.hidden { display: none !important; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.module {
  display: none;
  padding: 1rem 0 2rem;
}

.module.active { display: block; }

.module-head {
  margin-bottom: 1rem;
}

.module-head span {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.88rem;
}

.module-head h2 {
  font-size: 1.7rem;
  letter-spacing: 0;
}

.module-head p { color: var(--muted); max-width: 850px; }

.grid {
  display: grid;
  gap: 1rem;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.terminal-grid { grid-template-columns: minmax(460px, 1.25fr) minmax(320px, 0.75fr); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  min-width: 0;
}

.panel h3 { margin: 0 0 0.8rem; }
.trace + h3 { margin-top: 1rem; }
.panel h4 { margin: 0.3rem 0; }
.panel-note {
  margin: -0.25rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

label {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.88rem;
}

select, input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  color: var(--ink);
  background: #fff;
}

.flow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  text-align: center;
}

.flow div, .badge, .graph span {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.75rem;
  background: #f8fafc;
}

.flow div {
  display: grid;
  gap: 0.35rem;
  align-content: center;
  min-height: 86px;
}

.flow span {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.flow .wide { grid-column: 1 / -1; border-color: var(--accent); }
.flow .decision { grid-column: 1 / -1; border-color: var(--accent-2); }
.flow .decision strong { font-weight: 800; }

.trace {
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.85rem;
  min-height: 96px;
}

.policy-rules {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 0.85rem;
  margin-bottom: 0.8rem;
}

.policy-rules ul {
  margin: 0.45rem 0 0;
  padding-left: 1.1rem;
}

.policy-rules li + li {
  margin-top: 0.25rem;
}

.inline-control {
  margin: 0.65rem 0;
  max-width: 260px;
}

.allow { color: var(--allow); font-weight: 800; }
.deny { color: var(--deny); font-weight: 800; }
.warn { color: var(--warn); font-weight: 800; }

.matrix-table {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem;
  text-align: left;
  vertical-align: top;
}

td button {
  min-width: 56px;
  padding: 0.35rem 0.45rem;
}

.acl-view, .permission-view, .checklist {
  display: grid;
  gap: 0.45rem;
}

.challenge {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.challenge p { margin: 0.35rem 0 0.65rem; }
.challenge-top { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }

.check {
  display: flex;
  gap: 0.45rem;
  align-items: flex-start;
}

.check.ok { color: var(--allow); }
.check.bad { color: var(--deny); }

.exercise-list {
  display: grid;
  gap: 0.45rem;
}

.exercise-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem;
}

.exercise-number {
  display: grid;
  place-items: center;
  width: 1.6rem;
  aspect-ratio: 1;
  border-radius: 999px;
  background: #e8f2f5;
  font-weight: 700;
  color: var(--accent);
}

.exercise-question {
  min-width: 0;
}

.exercise-feedback {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.exercise-actions {
  display: flex;
  gap: 0.35rem;
}

.exercise-actions button {
  min-width: 48px;
  padding: 0.4rem 0.55rem;
  background: #fff;
}

.exercise-item.answer-ok {
  border-color: var(--allow);
  background: #f0f8f2;
}

.exercise-item.answer-bad {
  border-color: var(--deny);
  background: #fff5f3;
}

.needs-input {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.18);
  animation: inputPulse 900ms ease;
}

@keyframes inputPulse {
  0% { transform: translateY(0); }
  35% { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

.learn {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-left: 4px solid var(--accent-2);
  background: #eff8ed;
  border-radius: 6px;
}

.terminal-panel {
  background: var(--terminal);
  color: #f3f7fb;
}

.dac-scenario {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.dac-scenario div {
  display: grid;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 0.75rem;
}

.dac-scenario span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.unix-breakdown {
  display: grid;
  gap: 0.75rem;
}

.unix-breakdown code {
  display: block;
  padding: 0.8rem;
  border-radius: 8px;
  background: #101820;
  color: #f3f7fb;
  overflow-x: auto;
}

.unix-parts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.unix-parts div {
  display: grid;
  gap: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 0.7rem;
}

.unix-parts strong {
  color: var(--accent);
  font-size: 1.05rem;
}

.unix-parts span {
  color: var(--muted);
}

.terminal-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.6rem;
}

.terminal-toolbar button {
  background: #172532;
  color: #f3f7fb;
  border-color: #34475a;
}

.terminal-output {
  height: 430px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.45;
}

.terminal-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.terminal-form input {
  background: transparent;
  border: 0;
  color: #fff;
  outline: 0;
  padding: 0.2rem;
}

.perm-table .yes { color: var(--allow); font-weight: 700; }
.perm-table .no { color: var(--deny); font-weight: 700; }

.hint {
  color: var(--warn);
  margin-top: 0.6rem;
}

.label-ladder {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.label-ladder span {
  text-align: center;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  font-size: 0.85rem;
  font-weight: 700;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.28rem 0;
  color: var(--ink);
}

.check-row input { width: auto; }

.attribute-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.attr-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  background: #f8fafc;
}

.attr-card h4 { margin: 0 0 0.55rem; }
.policy-box {
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 0.8rem;
  margin-bottom: 0.8rem;
  background: #f6fbfd;
}

.policy-expression {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.65rem;
  line-height: 1.5;
}

.policy-expression span {
  border: 1px solid #9bd0df;
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
  background: #ffffff;
  color: #0f5f72;
  font-size: 0.78rem;
  font-weight: 800;
}

.graph {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  text-align: center;
}

.graph b { color: var(--accent); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .hero, .grid.two, .terminal-grid { grid-template-columns: 1fr; }
  .form-grid, .attribute-grid, .rbac-columns, .dac-scenario, .unix-parts { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  main, .sidebar { padding: 0.85rem; }
  .hero h2 { font-size: 1.45rem; }
  .label-ladder, .graph { grid-template-columns: 1fr; }
}
