/* ── Base ───────────────────────────────────────────────── */
body {
    font-family: 'Exo 2', Tahoma, sans-serif;
    margin: 10px;
    padding: 0;
    background: linear-gradient(to bottom, #D4E0F7, #b8caf0);
    background-image: url('/static/sixhack_bg.svg');
    background-size: cover;
    background-attachment: fixed;
    color: #210934;
}

header {
    background: SteelBlue;
    color: #D4E0F7;
    padding: 6px 14px 0 14px;
}

#header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#header-title h1 {
    margin: 0;
    font-size: 1.4em;
    font-weight: 700;
    color: #D4E0F7;
    white-space: nowrap;
    display: flex;
    flex-direction: column;
    gap: 0.1em;
}

#header-brand {
    font-family: 'Kode Mono', monospace;
    font-weight: 700;
    letter-spacing: -0.02em;
}

#header-subtitle {
    font-weight: 400;
    font-style: italic;
    font-size: 0.65em;
    opacity: 0.75;
    letter-spacing: 0.01em;
}

h2 { text-align: center; margin-top: 15px; }
p  { margin-left: 20px; }

nav { margin: 0; display: flex; align-items: center; gap: 4px; }

nav a {
    color: #D4E0F7;
    text-decoration: none;
    padding: 6px 12px;
    font-size: 14px;
}

nav a:hover { background: #e8491d; border-radius: 4px; }

/* ── Level bar ──────────────────────────────────────────── */
#level-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 8px 0 10px 0;
    align-items: center;
}

.level-item {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Border wrapper — clip-path clips box-shadow, so we use a slightly larger
   same-shape div behind the hex to fake a border */
.level-hex-wrap {
    --border-color: #D4E0F7;
    position: relative;
    width: 40px;
    height: 36px;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: -3px;
    cursor: pointer;
    transition: filter 0.2s;
}

.level-hex-wrap.diff-easy   { --border-color: #7fd67f; }
.level-hex-wrap.diff-medium { --border-color: #f0c040; }
.level-hex-wrap.diff-hard   { --border-color: #e06060; }

.level-hex-wrap.active { --border-color: #fff; filter: brightness(1.2) saturate(1.4); }
.level-hex-wrap:hover  { filter: brightness(1.25); }

.level-hex {
    --fill-pct: 0%;
    width: 34px;
    height: 30px;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    background: linear-gradient(to top, #700CBC var(--fill-pct), #1a6090 var(--fill-pct));
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.level-hex span {
    font-size: 11px;
    font-weight: 700;
    color: #D4E0F7;
    user-select: none;
    pointer-events: none;
}

/* ── Header scores ──────────────────────────────────────── */
#header-scores {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 14px;
    white-space: nowrap;
}

.score-box {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 60, 0.35);
    border: 2px solid #D4E0F7;
    border-radius: 6px;
    padding: 2px 10px 2px 8px;
    color: #c49ad8;
    font-weight: 700;
    font-size: 0.9em;
}

.score-box-total {
    color: #D4E0F7;
    font-size: 1em;
}

.score-symbol {
    font-size: 1em;
    font-weight: 900;
    color: #D4E0F7;
    opacity: 0.8;
}

.score-symbol-sigma {
    font-size: 1.3em;
    line-height: 1;
}

.level-tooltip {
    display: none;
    position: absolute;
    z-index: 5000;
    max-width: 300px;
    background: #fff;
    border: 1px solid #1258DC;
    color: #210934;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 0.88em;
    box-shadow: 0 2px 8px rgba(18, 88, 220, 0.2);
    pointer-events: none;
    white-space: normal;
    line-height: 1.4;
}

/* ── Instructions panel ─────────────────────────────────── */
#instructions-panel {
    border: 2px solid #1258DC;
    border-radius: 6px;
    margin-bottom: 6px;
    background: #eef2fc;
    overflow: hidden;
}

#instructions-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    flex-wrap: wrap;
    min-height: 60px;
}

#instructions-goal {
    font-weight: 600;
    font-size: 0.95em;
    flex: 1;
    min-width: 0;
}

#instructions-badges {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.badge {
    font-size: 0.72em;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-gcse     { background: #d0e8ff; color: #1258DC; }
.badge-a_level  { background: #e8d0ff; color: #700CBC; }
.badge-topic    { background: #d8f0d8; color: #2a7a2a; }

.hints-toggle {
    font-size: 12px;
    padding: 3px 9px;
    margin: 0;
    height: auto;
    border-radius: 4px;
    flex-shrink: 0;
}

.hints-toggle:disabled {
    opacity: 0.35;
    cursor: default;
}

#instructions-detail {
    display: none;
    padding: 0 12px 8px 12px;
    border-top: 1px solid #c8d4f0;
}

#instructions-detail.open { display: block; }

#hints-list {
    margin: 6px 0 0 0;
    padding-left: 18px;
    font-size: 0.88em;
    line-height: 1.7;
}

#theme-toggle {
    background: none;
    border: none;
    box-shadow: none;
    font-size: 20px;
    padding: 6px 10px;
    margin: 0;
    cursor: pointer;
    vertical-align: middle;
}

#theme-toggle:active {
    background: none;
    box-shadow: none;
}

/* ── Layout ─────────────────────────────────────────────── */
.flex-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 6px;
    margin-top: 10px;
}

.sandbox-container {
    flex: 1;
    max-width: 100%;
    margin-top: 6px;
    margin-bottom: 10px;
}

.output-container {
    flex: 1;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-left: 6px;
}

/* ── Buttons ────────────────────────────────────────────── */
button {
    font-family: 'Exo 2', Tahoma, sans-serif;
    font-size: 14px;
    padding: 10px 15px;
    margin: 5px;
    border: 2px solid #1258DC;
    border-radius: 5px;
    background: linear-gradient(to bottom, #1258DC, #2E2FE3);
    color: #ffffff;
    box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3);
    cursor: pointer;
}

button:hover {
    background: linear-gradient(to bottom, #700CBC, #2E2FE3);
    border-color: #700CBC;
}

button:active {
    background: linear-gradient(to bottom, #2E2FE3, #1258DC);
    box-shadow: inset 2px 2px 2px rgba(0, 0, 0, 0.4);
}

.bottom-buttons {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.copyright {
    font-size: 8pt;
    color: #555;
    text-align: right;
    margin-top: 4px;
    padding-right: 5px;
}

.copyright a {
    color: #1258DC;
    text-decoration: none;
}

.copyright a:hover { text-decoration: underline; }

body.dark .copyright { color: #888; }
body.dark .copyright a { color: #7ab3f5; }

/* ── Form controls ──────────────────────────────────────── */
textarea,
input,
select {
    font-family: "Lucida Console", monospace;
    background: #ffffff;
    color: #210934;
    border: 2px solid #1258DC;
    box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
}


/* ── Input row (clear / run / input box) ────────────────── */
.test-container {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 6px;
}

#clear-button,
#run-button {
    padding: 0;
    margin: 0;
    width: 64px;
    height: 64px;
    font-size: 20px;
    border-radius: 5px;
    border: 2px solid #1258DC;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: none;
}

#run-button  { background: #1258DC; color: white; }
#run-button:hover { background: #700CBC; border-color: #700CBC; }

#clear-button { background: #b8caf0; color: white; border-color: #8aaad8; }
#clear-button:hover { background: #9ab8e8; border-color: #700CBC; }

#input-box {
    flex: 1;
    height: 64px;
    font-family: "Lucida Console", monospace;
    font-size: 14px;
    padding: 10px;
    line-height: 20px;
    background-color: #eef2fc;
    color: #210934;
    border: 2px solid #1258DC;
    border-radius: 5px;
    box-sizing: border-box;
}

/* ── Tab buttons (shared by style tabs and test case tabs) ─ */
#code-tabs,
#tab-buttons {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    width: 100%;
}

#tab-buttons {
    margin-top: 6px;
    flex-wrap: nowrap;
    overflow: visible;
    width: calc(100% - 2px);
}

#tab-buttons .tab-button {
    flex: 1 1 0;
    min-width: 28px;
    padding: 0 6px;
    font-size: 12px;
    margin-right: -2px;  /* overlap borders so they don't stack up */
}

#tab-buttons .tab-button.active {
    z-index: 2;
    margin-right: -2px;
}

.tab-button {
    padding: 0 15px;
    margin: 0;
    height: 40px;
    box-shadow: none;
    border: 2px solid #1258DC;
    background: linear-gradient(to right, #b8caf0, #d4e0f7);
    color: #210934;
    cursor: pointer;
    border-radius: 10px 10px 0 0;
    font-size: 14px;
    flex: 1;
    min-width: 0;
    text-align: center;
    transition: background 0.3s;
    position: relative;
    z-index: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.tab-button:hover { background: linear-gradient(to right, #a0bce8, #b8caf0); }

.tab-button.active {
    font-weight: bold;
    background: linear-gradient(to right, #1a6090, #1258DC);
    border-color: #1258DC;
    border-bottom: none;
    color: #ffffff;
}

/* ── Output window ──────────────────────────────────────── */
#output-window {
    color: #fff;
    background: #222;
    padding: 12px;
    margin-top: 0;
    border-radius: 0 0 8px 8px;
    font-family: monospace;
}

#output {
    font-family: "Lucida Console", monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: white;
}

#output:empty::before {
    content: "Output will appear here...";
    color: gray;
    font-size: 0.85em;
}

.output-error   { color: #cc2200; }
.output-penalty { color: #cc2200; font-size: 0.85em; }
.output-result  { font-weight: bold; }
.output-test    { margin-bottom: 8px; }

/* Rich feedback block */
.fb-block        { font-size: 0.92em; line-height: 1.6; }
.fb-summary      { font-weight: 600; font-size: 1.05em; margin-bottom: 10px; }
.fb-pass         { color: #1a7a3a; }
.fb-partial      { color: #7a5c00; }
.fb-fail         { color: #9a1a1a; }
.fb-tests        { margin: 0 0 4px 0; }
.fb-test         { margin: 4px 0; padding: 4px 8px; border-radius: 4px; }
.fb-test-pass    { background: #eaf7ee; }
.fb-test-fail    { background: #fdf0f0; }
.fb-test-icon    { margin-right: 4px; }
.fb-hint         { font-size: 0.88em; color: #555; margin-left: 20px; }
.fb-deduction    { font-size: 0.82em; color: #cc2200; font-style: italic; margin-left: 6px; }
.fb-divider      { margin: 10px 0; border: none; border-top: 1px solid #ddd; }
.fb-style        { margin: 4px 0; }
.fb-style-label  { font-weight: 600; font-size: 0.85em; text-transform: uppercase;
                   letter-spacing: 0.05em; color: #666; margin-bottom: 4px; }
.fb-style-msg    { margin: 2px 0 2px 4px; font-size: 0.9em; }
.fb-style-ok     { color: #1a7a3a; }
.fb-score        { font-size: 1em; margin-top: 6px; }
.fb-score-full   { color: #1a7a3a; }
.fb-score-zero   { color: #9a1a1a; }

/* ── CodeMirror ─────────────────────────────────────────── */
.CodeMirror {
    font-size: 15px;
    border: 2px solid #1258DC;
    border-top: none;
    border-radius: 0 0 5px 5px;
}


/* ── Tab copy popover ───────────────────────────────────── */
#tab-copy-popover {
    display: none;
    position: fixed;
    z-index: 8000;
    background: #ffffff;
    border: 2px solid #1258DC;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(18, 88, 220, 0.2);
    padding: 6px 0;
    min-width: 160px;
    font-family: 'Exo 2', Tahoma, sans-serif;
    font-size: 13px;
}

#tab-copy-popover .popover-title {
    padding: 4px 12px 6px;
    font-weight: 600;
    color: #1258DC;
    border-bottom: 1px solid #d0dcf4;
    margin-bottom: 4px;
}

#tab-copy-popover button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 5px 12px;
    margin: 0;
    border: none;
    border-radius: 0;
    background: none;
    box-shadow: none;
    color: #210934;
    font-size: 13px;
    cursor: pointer;
}

#tab-copy-popover button:hover {
    background: #d4e0f7;
    border: none;
    color: #210934;
}

#tab-copy-popover .popover-all {
    border-top: 1px solid #d0dcf4;
    margin-top: 4px;
    padding-top: 4px;
    font-weight: 600;
    color: #700CBC;
}

body.dark #tab-copy-popover {
    background: #1e2a35;
    border-color: #1258DC;
}

body.dark #tab-copy-popover .popover-title {
    color: #7ab3f5;
    border-bottom-color: #2e3f4f;
}

body.dark #tab-copy-popover button {
    color: #d8d8d8;
}

body.dark #tab-copy-popover button:hover {
    background: #2e3f4f;
    color: #d8d8d8;
}

body.dark #tab-copy-popover .popover-all {
    border-top-color: #2e3f4f;
    color: #c49ad8;
}

/* ── Tooltip ────────────────────────────────────────────── */
.tab-tooltip {
    display: none;
    position: absolute;
    z-index: 1000;
    max-width: 400px;
    background: #fff;
    border: 1px solid #1258DC;
    color: #210934;
    padding: 8px;
    border-radius: 6px;
    white-space: pre-wrap;
    font-size: 0.95em;
    box-shadow: 0 2px 8px rgba(18, 88, 220, 0.2);
}

/* ── Intro modal ────────────────────────────────────────── */
#intro-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#intro-modal {
    background: #ffffff;
    color: #210934;
    border: 2px solid #1258DC;
    border-radius: 10px;
    padding: 32px 36px;
    max-width: 540px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(18, 88, 220, 0.25);
    font-family: 'Exo 2', Tahoma, sans-serif;
}

#intro-modal h2 { margin-top: 0; color: #1258DC; }
#intro-modal p  { margin-left: 0; line-height: 1.6; }
#intro-modal ul { padding-left: 20px; line-height: 1.8; }

#intro-modal .modal-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

#intro-modal .modal-buttons label {
    font-size: 13px;
    color: #555;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

/* ── Legacy element suppression ─────────────────────────── */
/* Hides any old meter/progress elements that may remain in saved HTML */
meter,
[id^="meter-label-"],
.meter-container,
.meter-feedback {
    display: none !important;
}

/* ── Light theme overrides ──────────────────────────────── */
body:not(.dark) #output-window {
    background: #ffffff;
    color: #210934;
    border: 2px solid #1258DC;
    border-top: none;
}

body:not(.dark) #output { color: #210934; }

body:not(.dark) #output:empty::before { color: #888; }

/* ── Dark theme ─────────────────────────────────────────── */
body.dark {
    background: linear-gradient(to bottom, midnightblue, darkslategray);
    background-image: url('/static/sixhack_bg.svg');
    background-size: cover;
    background-attachment: fixed;
    color: #d8d8d8;
}

body.dark::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 30, 0.78);
    pointer-events: none;
    z-index: -1;
}

body.dark header { background: MidnightBlue; }

body.dark #header-title h1 { color: #D4E0F7; }

body.dark .level-hex {
    background: linear-gradient(to top, #700CBC var(--fill-pct), #1a2a40 var(--fill-pct));
}

body.dark .score-box {
    background: rgba(0, 0, 40, 0.5);
    border-color: #4a6a9a;
}

body.dark .level-tooltip {
    background: #1e2a35;
    border-color: #555;
    color: #d8d8d8;
}

body.dark #instructions-panel {
    background: #1a2a35;
    border-color: #1258DC;
}

body.dark #instructions-detail { border-top-color: #2e3f4f; }

body.dark .badge-gcse    { background: #1a2a40; color: #7ab3f5; }
body.dark .badge-a_level { background: #2a1a40; color: #c49ad8; }
body.dark .badge-topic   { background: #1a2a1a; color: #7fd67f; }

body.dark .tab-button {
    background: linear-gradient(to right, #333, #111);
    border-color: #1258DC;
    color: #d8d8d8;
}

body.dark .tab-button:hover { background: linear-gradient(to right, #444, #222); }

body.dark .tab-tooltip {
    background: #1e2a35;
    border-color: #555;
    color: #d8d8d8;
}

body.dark textarea,
body.dark input,
body.dark select {
    background: linear-gradient(to bottom, #1e2a35, #162028);
    color: #d8d8d8;
    border-color: #1258DC;
}

body.dark #input-box {
    background: #1e2a35;
    color: #d8d8d8;
}


body.dark button {
    background: linear-gradient(to bottom, #2e3f4f, #1a2a35);
    color: #d8d8d8;
    border-color: #1258DC;
}

body.dark button:active {
    background: linear-gradient(to bottom, #1a2a35, #2e3f4f);
}

body.dark #clear-button {
    background: #2e3f4f;
    color: #d8d8d8;
    border: 2px solid #4a6a9a;
}

body.dark #clear-button:hover { background: #700CBC; border-color: #700CBC; }

body.dark #run-button {
    background: steelblue;
    border: 2px solid #1258DC;
    color: #d8d8d8;
}

body.dark .output-error,
body.dark .output-penalty { color: #ff6666; }

body.dark .fb-pass         { color: #5dbb7a; }
body.dark .fb-partial      { color: #e0b84a; }
body.dark .fb-fail         { color: #e07070; }
body.dark .fb-test-pass    { background: #1a2e1f; }
body.dark .fb-test-fail    { background: #2e1a1a; }
body.dark .fb-hint         { color: #aaa; }
body.dark .fb-deduction    { color: #ff6666; }
body.dark .fb-divider      { border-color: #444; }
body.dark .fb-style-label  { color: #999; }
body.dark .fb-style-ok     { color: #5dbb7a; }
body.dark .fb-score-full   { color: #5dbb7a; }
body.dark .fb-score-zero   { color: #e07070; }

body.dark #output-window {
    border: 2px solid #1258DC;
    border-top: none;
    color: #d8d8d8;
}

body.dark .CodeMirror { border-color: #1258DC; }


body.dark #intro-modal {
    background: #1e2a35;
    color: #d8d8d8;
    border-color: #1258DC;
}

body.dark #intro-modal h2 { color: #7ab3f5; }

body.dark #intro-modal .modal-buttons label { color: #aaa; }
