/*
 * workspace.css — Trang làm bài: khung đề (trái), editor + console kết quả (phải), bài đoán kết quả.
 */
.workspace {
  --left-w: 42%;
  height: calc(100dvh - var(--header-h));
  display: flex; flex-direction: column;
}
.ws-top {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.crumb { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.ws-main { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--left-w) 6px minmax(0, 1fr); gap: 0; padding: 8px; }
.ws-left, .ws-right { min-height: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.ws-split { cursor: col-resize; border-radius: 4px; margin: 0 1px; touch-action: none; }
.ws-split:hover, .ws-split:active { background: var(--primary-soft); }

/* ----- Khung đề ----- */
.desc-panel { display: flex; flex-direction: column; }
.desc-tabs, .console-tabs {
  display: flex; gap: 2px; padding: 4px 6px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  overflow-x: auto; flex: none;
}
.dtab, .ctab {
  font: inherit; font-size: 0.86rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
}
.dtab:hover, .ctab:hover { color: var(--text); background: var(--surface-3); }
.dtab.active, .ctab.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.dtab.locked { color: var(--muted); }
.dtab .icon { width: 13px; height: 13px; margin-right: 4px; }
.desc-body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; }
.p-title { font-size: 1.35rem; }
.p-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.story {
  border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin-bottom: 14px;
  color: var(--muted); font-style: italic;
}
.story p { margin: 0; display: inline; }
.rules { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; font-weight: 600; }
.example { margin: 14px 0; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); }
.example h4 { margin: 0 0 6px; }
.example label, .io-grid label, .test-detail label, .files label, .predict-reveal label, .kv label {
  display: block; font-size: 0.76rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin: 6px 0 3px;
}
.example pre.io { margin-bottom: 4px; background: var(--surface); }
.review-banner { background: var(--accent-soft); border: 1px dashed var(--accent); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.hint { padding: 10px 14px; border-radius: 10px; margin: 8px 0; background: var(--surface-2); }
.hint.open { background: var(--accent-soft); }
.hint.locked { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.hint.next { width: 100%; font: inherit; font-weight: 700; cursor: pointer; text-align: left; border: 2px dashed var(--accent); background: transparent; color: var(--text); }
.hint .md p:last-child { margin: 0; }
.locked-box { background: var(--surface-2); border-radius: 10px; padding: 14px; color: var(--muted); }
.locked-box .btn { margin-top: 10px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 12px; color: var(--muted); }
.history { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.history td { padding: 6px 8px; border-bottom: 1px solid var(--border); }

/* ----- Editor ----- */
.ws-right { display: flex; flex-direction: column; }
.editor-wrap { flex: 1 1 58%; min-height: 160px; display: flex; flex-direction: column; border-bottom: 1px solid var(--border); }
.editor-panel { display: flex; flex-direction: column; }
.editor-toolbar { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex: none; }
.editor-toolbar .lang { font-weight: 700; font-size: 0.85rem; padding-left: 4px; }
.editor-toolbar .icon-btn { border-color: transparent; background: transparent; font-weight: 700; }
.editor-host { flex: 1; min-height: 0; position: relative; }
.editor-host .CodeMirror { position: absolute; inset: 0; height: 100%; font-family: var(--mono); font-size: inherit; line-height: 1.55; background: var(--surface); }
.cm-s-material-darker.CodeMirror, .cm-s-material-darker .CodeMirror-gutters { background: var(--code-bg); }
.CodeMirror-gutters { background: var(--surface-2); border-right: 1px solid var(--border); }
.CodeMirror-linenumber { color: var(--muted); }
.cm-s-default .CodeMirror-activeline-background { background: var(--primary-soft); }
.cm-error-line { background: var(--bad-soft) !important; box-shadow: inset 3px 0 0 var(--bad); }

/* ----- Console kết quả ----- */
.console-wrap { flex: 1 1 42%; min-height: 150px; display: flex; flex-direction: column; }
.result-console { display: flex; flex-direction: column; }
.console-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; }
.console-placeholder { color: var(--muted); padding: 8px 2px; }
.verdict { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 10px; }
.verdict b { font-size: 1.3rem; font-weight: 800; }
.verdict.good b { color: var(--good); }
.verdict.bad b { color: var(--bad); }
.verdict-sub { color: var(--muted); font-size: 0.9rem; }
.reward {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px;
  padding: 10px 14px; border-radius: 10px; background: var(--good-soft);
}
.rule-error { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; font-weight: 600; }
.test-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.test-chip {
  font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer; padding: 4px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.test-chip::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.test-chip.pass::before { background: var(--good); }
.test-chip.fail::before { background: var(--bad); }
.test-chip.active { border-color: var(--text); background: var(--surface); }
.test-head { font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.kv { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 4px 0; }
.kv label { margin: 0; min-width: 84px; }
.kv code.bad { background: var(--bad-soft); color: var(--bad); }
.io-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
pre.io { white-space: pre; }
pre.io .ln { display: block; min-height: 1.5em; }
pre.io .ln.bad { background: var(--bad-soft); color: var(--bad); margin: 0 -12px; padding: 0 12px; }
pre.io .ln.good { color: var(--good); }
pre.io .ln.empty { color: var(--muted); font-style: italic; }
pre.terminal { background: #0f1520; color: #d8e1ee; border-color: #0f1520; }
.error-box { border: 1px solid var(--bad); background: var(--bad-soft); border-radius: 10px; padding: 10px 14px; margin: 10px 0; display: grid; gap: 6px; }
.error-title { color: var(--bad); }
.error-line { margin: 0; background: var(--surface); padding: 6px 10px; border-radius: 6px; font-size: 0.88rem; overflow-x: auto; }
.error-line .lno { color: var(--muted); }
.error-msg code { background: transparent; padding: 0; }
.error-hint { font-weight: 600; }
.error-box .btn { justify-self: start; }
.file-check p.bad, p.bad { color: var(--bad); }
.files details { margin-bottom: 6px; }
.files summary { cursor: pointer; font-weight: 600; }
.free-label { font-size: 0.86rem; color: var(--muted); }
.stdin-box, .predict-input {
  width: 100%; resize: vertical; font-size: 0.92rem; padding: 8px 10px; margin: 6px 0;
  border-radius: 8px; border: 1px solid var(--border); background: var(--code-bg); color: var(--text);
}
.free-actions, .predict-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.action-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface-2); flex: none; }
.run-status { margin-right: auto; font-size: 0.85rem; }

/* ----- Bài đoán kết quả ----- */
.ws-right.is-predict { overflow-y: auto; }
.predict-host { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.predict-panel { padding: 14px 16px; display: grid; gap: 14px; align-content: start; }
.pane-label { display: block; font-weight: 700; margin-bottom: 6px; }
.predict-code { height: 260px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.predict-input { min-height: 130px; }

@media (max-width: 900px) {
  .workspace { height: auto; }
  .ws-main { grid-template-columns: 1fr; gap: 10px; }
  .ws-split { display: none; }
  .ws-left { max-height: none; }
  .desc-body { max-height: 55vh; }
  .editor-wrap { min-height: 52vh; flex: none; }
  .console-wrap { min-height: 260px; flex: none; }
  .action-bar { position: sticky; bottom: 0; z-index: 5; }
  .io-grid { grid-template-columns: 1fr; }
  .crumb { font-size: 0.8rem; }
}
