/* ============================================================
   IWS Kodowanie – Style Aplikacji Ucznia (/iwskodowanie/)
   Zero zależności zewnętrznych, pełna zgodność z RODO.
   ============================================================ */

:root {
  --navy: #1A0933;
  --navy-2: #2a1250;
  --navy-3: #7C3AED;
  --violet: #7C3AED;
  --pink: #DB2777;
  --yellow: #F3DB52;
  --orange: #E89C40;
  --green: #7BCE88;
  --blue: #80B2F7;
  --red: #CE6752;
  --paper: #FBF9FF;
  --panel: #FFFFFF;
  --line: #E6DFF3;
  --ink: #1A0933;
  --ink-soft: #5b4d78;
  --font: "Exo 2", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

/* ============ Przyciski i elementy bazowe ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  border: 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  padding: .65rem 1.2rem;
  border-radius: 999px;
  transition: transform .08s ease, filter .15s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 1.05em; height: 1.05em; flex: none; }
.btn-run { background: var(--green); color: #06361b; }
.btn-check { background: var(--blue); color: #08294a; }
.btn-send { background: var(--yellow); color: var(--navy); }
.btn-run:hover, .btn-check:hover, .btn-send:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: #d9ccf0; padding: .55rem .9rem; font-weight: 600; }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-big { padding: .85rem 1.6rem; font-size: 1.1rem; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-3); }
.btn-outline { background: #fff; color: var(--navy); border: 2px solid var(--line); padding: .5rem 1rem; }
.btn-outline:hover { border-color: var(--blue); }
.btn-orange { background: var(--orange); color: #3a1d00; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: .35rem .8rem; font-size: .9rem; }

.logo { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; color: #fff; }
.logo svg { width: 38px; height: 38px; flex: none; }
.logo b { font-weight: 800; font-size: 1.15rem; letter-spacing: .01em; }
.logo small { display: block; font-family: var(--mono); font-size: .72rem; color: var(--green); font-weight: 500; margin-top: -2px; }

.t-meta { font-size: .85rem; font-weight: 700; padding: .2rem .65rem; border-radius: 999px; white-space: nowrap; }
.t-meta.deadline, .t-meta.s-return { background: #ffe0b8; color: #8a4a00; }
.t-meta.s-ok, .t-meta.s-graded { background: #d9f7e6; color: #11663a; }
.t-meta.s-sent { background: #dff0ff; color: #1b5a95; }
.t-meta.s-todo { background: #f0eafa; color: var(--ink-soft); }
.t-meta.s-progress { background: #ece3ff; color: #5a2fa8; }
.chip { display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-size: .85rem; font-weight: 700; }
.chip.test { background: #ffe0b8; color: #8a4a00; }
.chip.ex { background: #dff0ff; color: #1b5a95; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--navy); color: #fff; padding: .8rem 1.3rem; border-radius: 999px; font-weight: 700; max-width: 90vw;
  border: 2px solid var(--green); box-shadow: 0 12px 30px #0006; transition: .25s ease; pointer-events: none; z-index: 100; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

dialog { border: 0; border-radius: 18px; padding: 1.5rem 1.6rem; width: min(440px, 92vw); color: var(--ink); box-shadow: 0 30px 60px -20px #000a; }
dialog::backdrop { background: #1a093399; }
dialog h2 { margin: 0 0 .4rem; font-size: 1.3rem; font-weight: 800; }
dialog p { margin: 0 0 1.2rem; color: var(--ink-soft); }
dialog .row { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; }

/* ============ Pasek aplikacji z zakładkami ============ */
.topbar {
  background: linear-gradient(90deg, var(--navy) 0%, var(--violet) 62%, var(--pink) 100%);
  color: #fff;
  display: flex;
  align-items: stretch;
  gap: .8rem;
  padding: 0 1.25rem;
  min-height: 62px;
  flex: none;
  z-index: 10;
}
.topbar .logo, .topbar .who, .topbar > .btn { align-self: center; }
.topbar .spacer { flex: 1; }
.tabs { display: flex; gap: .15rem; margin-left: 1rem; align-items: stretch; }
.tabs button {
  background: none; border: 0; border-bottom: 4px solid transparent; color: #cdbdea; font-weight: 700; font-size: 1.05rem;
  padding: 0 1.1rem; cursor: pointer; display: inline-flex; align-items: center; gap: .5rem;
}
.tabs button:hover { color: #fff; background: #ffffff12; }
.tabs button[aria-current="page"] { color: #fff; border-bottom-color: var(--yellow); }
.tabs button.tab-test[aria-current="page"] { border-bottom-color: var(--orange); }
.tabs .badge {
  background: var(--orange); color: #3a1d00; font-size: .78rem; font-weight: 800; min-width: 1.35rem; height: 1.35rem;
  border-radius: 999px; display: inline-grid; place-items: center; padding: 0 .35rem;
}
.who { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.who .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--yellow); color: var(--navy); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.who .who-text { line-height: 1.2; text-align: right; }
.who .who-text small { display: block; color: #bda9de; font-weight: 500; font-size: .8rem; }

#app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#app > section { flex: 1; min-height: 0; overflow: auto; }

/* ============ Logowanie ============ */
#screen-login {
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  background: radial-gradient(900px 500px at 15% 10%, #7C3AED55, transparent 60%), radial-gradient(700px 500px at 90% 95%, #E89C4022, transparent 60%), var(--navy);
}
.bg-graph { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .18; pointer-events: none; }
.login-wrap { position: relative; width: min(440px, 100%); }
.login-brand { display: flex; justify-content: center; margin-bottom: 1.5rem; }
.login-brand .logo b { font-size: 1.5rem; }
.login-brand .logo svg { width: 50px; height: 50px; }
.login-card { background: var(--panel); border-radius: 20px; padding: 2rem 1.75rem 1.5rem; box-shadow: 0 30px 60px -20px #000a; }
.login-card h1 { margin: 0 0 .25rem; font-size: 1.6rem; font-weight: 800; }
.login-card p.lead { margin: 0 0 1.4rem; color: var(--ink-soft); }
.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 700; margin-bottom: .35rem; }
.field input {
  width: 100%; padding: .8rem 1rem; font-family: var(--mono); font-size: 1.25rem; letter-spacing: .12em;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: #fcfaff; color: var(--ink);
}
.field input::placeholder { color: #b7abcf; }
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px #80B2F733; }
.login-msg { padding: .7rem .9rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-weight: 600; border-left: 5px solid var(--red); background: #fdecea; color: #8f2615; }
.login-msg.blocked { border-left-color: var(--orange); background: #fff1dc; color: #7a4100; }
.login-card .btn { width: 100%; justify-content: center; }
.login-info { margin: 1rem 0 0; font-size: .9rem; color: var(--ink-soft); text-align: center; }
.login-back { text-align: center; margin-top: 1.1rem; }
.login-back a { color: #cdbdea; text-decoration: none; font-weight: 600; }
.login-back a:hover { color: #fff; text-decoration: underline; }

/* ============ Listy (Wiedza, Ćwiczenia, Test) ============ */
.main-col { max-width: 920px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.main-col h1 { font-size: 2rem; font-weight: 800; margin: 0 0 .25rem; }
.main-col .lead { color: var(--ink-soft); margin: 0 0 2rem; max-width: 62ch; }
.group { margin-bottom: 2.2rem; }
.group > h2 { font-size: 1.25rem; font-weight: 800; margin: 0 0 .15rem; }
.group > p { margin: 0 0 .9rem; color: var(--ink-soft); font-size: .98rem; }
.group.mine { background: linear-gradient(135deg, #fff6d6, #ffe9c2); border: 2px solid var(--yellow); border-radius: 18px; padding: 1.25rem 1.25rem 1.1rem; }
.group.mine > h2 { display: flex; align-items: center; gap: .55rem; }
.group.mine > h2 svg { width: 24px; height: 24px; }
.group.test { background: #fff4e5; border: 2px solid var(--orange); border-radius: 18px; padding: 1.25rem 1.25rem 1.1rem; }
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.task {
  display: flex; align-items: center; gap: .9rem; width: 100%; background: var(--panel); border: 2px solid var(--line);
  border-radius: var(--radius); padding: .8rem 1rem; text-align: left; cursor: pointer; color: inherit; transition: border-color .15s ease, transform .1s ease;
}
.task:hover { border-color: var(--blue); transform: translateX(3px); }
.group.test .task:hover { border-color: var(--orange); }
.task .state { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; border: 2.5px solid #cfc3e6; color: transparent; background: #fff; }
.task .state svg { width: 18px; height: 18px; }
.task.s-ok .state, .task.s-graded .state { background: var(--green); border-color: var(--green); color: var(--navy); }
.task.s-sent .state { background: var(--blue); border-color: var(--blue); color: var(--navy); }
.task.s-return .state { background: var(--orange); border-color: var(--orange); color: var(--navy); }
.task.s-progress .state { border-color: #9b7ad8; color: #7a52c9; }
.task .t-body { flex: 1; min-width: 0; }
.task .t-title { font-weight: 700; display: block; }
.task .t-desc { font-size: .92rem; color: var(--ink-soft); display: block; }

/* ============ Lekcja (czytanie) ============ */
.lesson-read { max-width: 780px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.lesson-read .crumb { color: var(--ink-soft); font-weight: 600; margin: 0 0 .3rem; }
.lesson-read h1 { margin: 0 0 1rem; font-size: 2.1rem; font-weight: 800; line-height: 1.2; }
.lesson-read p { margin: .85rem 0; max-width: 68ch; }
.lesson-read .actions { margin-top: 2.5rem; display: flex; gap: .8rem; flex-wrap: wrap; }

code { font-family: var(--mono); font-size: .92em; background: #f1ebfb; color: #5b21b6; padding: .15em .45em; border-radius: 5px; }
pre.example {
  margin: 1rem 0 1.2rem; padding: 1.1rem 1.25rem; background: var(--navy); color: #eadfff;
  border-radius: var(--radius-sm); font-family: var(--mono); font-size: .95rem; line-height: 1.65;
  overflow-x: auto; box-shadow: inset 0 2px 6px #00000044;
}
pre.example code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
pre.example .c { color: var(--green); font-style: italic; }
pre.example .s { color: var(--yellow); }
pre.example .k { color: var(--blue); font-weight: 700; }
pre.example .n { color: #FFA07A; }

/* ============ Zadanie + edytor ============ */
#screen-work { display: flex; flex-direction: column; overflow: hidden; }
.test-strip { background: var(--orange); color: #3a1d00; font-weight: 700; padding: .45rem 1.25rem; flex: none; }
.work-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 5fr) 7fr; }
.lesson { overflow-y: auto; padding: 1.6rem 1.6rem 3rem; background: var(--panel); border-right: 2px solid var(--line); }
.lesson .crumb { color: var(--ink-soft); font-size: .92rem; margin: 0 0 .3rem; font-weight: 600; }
.lesson h1 { margin: 0 0 1rem; font-size: 1.7rem; font-weight: 800; line-height: 1.2; }
.lesson h2 { margin: 1.5rem 0 .4rem; font-size: 1.1rem; font-weight: 800; }
.lesson p { margin: .4rem 0; max-width: 62ch; }
.task-box { margin-top: 1.4rem; padding: 1rem 1.1rem; border-radius: var(--radius); background: #eaf6ff; border-left: 6px solid var(--blue); }
.task-box.is-test { background: #fff1dc; border-left-color: var(--orange); }
.task-box h2 { margin-top: 0; }
.task-box ul { margin: .3rem 0 0; padding-left: 1.2rem; }
details.hint { margin-top: 1rem; border: 2px dashed var(--line); border-radius: var(--radius); padding: .6rem 1rem; }
details.hint summary { cursor: pointer; font-weight: 700; color: var(--ink-soft); }
details.hint[open] { border-style: solid; border-color: var(--orange); background: #fff8ee; }
details.hint[open] summary { color: #8a4a00; margin-bottom: .4rem; }

.workspace { display: flex; flex-direction: column; min-height: 0; background: var(--navy); }
.toolbar { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; background: var(--navy-2); border-bottom: 1px solid #ffffff1a; flex-wrap: wrap; }
.toolbar .file { font-family: var(--mono); font-size: .88rem; color: #bda9de; }
.toolbar .save-state { font-size: .85rem; color: #9f8cc4; margin-right: auto; }
.banner { padding: .7rem 1rem; font-weight: 600; border-bottom: 1px solid #00000022; }
.banner b { display: block; }
.banner.sent { background: #dff0ff; color: #12446f; }
.banner.return { background: #ffe5c2; color: #6a3600; }
.banner.graded { background: #d9f7e6; color: #0d5230; }
.banner .grade { display: inline-grid; place-items: center; min-width: 2rem; height: 2rem; border-radius: 50%; background: #0d5230; color: #fff; margin-left: .4rem; font-weight: 800; }
.banner p { margin: .2rem 0 0; font-weight: 500; }

.editor { flex: 1 1 50%; min-height: 170px; display: flex; position: relative; overflow: hidden; }
.gutter { padding: 1rem .6rem 1rem .9rem; text-align: right; user-select: none; overflow: hidden; font-family: var(--mono); font-size: 1rem; line-height: 1.65; color: #7d6aa6; background: #150728; white-space: pre; }
#code { flex: 1; border: 0; resize: none; padding: 1rem 1rem 1rem .9rem; margin: 0; font-family: var(--mono); font-size: 1rem; line-height: 1.65; tab-size: 4; background: var(--navy); color: #f3ecff; caret-color: var(--yellow); white-space: pre; overflow: auto; }
#code:focus { outline: none; box-shadow: inset 0 0 0 2px #80B2F766; }
.editor.locked #code { background: #221044; color: #cbbfe6; cursor: not-allowed; }
.privacy { font-size: .82rem; color: #9f8cc4; padding: .3rem 1rem; background: #150728; }

.console { flex: 1 1 36%; min-height: 150px; display: flex; flex-direction: column; background: #0f0520; border-top: 2px solid #ffffff1a; min-height: 0; }
.console-head { display: flex; align-items: center; justify-content: space-between; padding: .45rem 1rem; color: #bda9de; font-weight: 700; font-size: .9rem; }
.console-head button { background: none; border: 0; color: #bda9de; cursor: pointer; font-weight: 600; }
.console-head button:hover { color: #fff; }
#output { flex: 1; margin: 0; padding: .2rem 1rem .6rem; overflow: auto; font-family: var(--mono); font-size: .98rem; line-height: 1.6; color: #d7f8e4; white-space: pre-wrap; min-height: 3rem; }
#output .muted { color: #8a7ab0; } #output .err { color: #ff9e8f; } #output .typed { color: var(--yellow); }
#stdin { display: flex; gap: .5rem; align-items: center; padding: .4rem 1rem .8rem; }
#stdin label { font-family: var(--mono); color: #d7f8e4; white-space: nowrap; }
#stdin input { flex: 1; min-width: 0; padding: .45rem .7rem; border-radius: 8px; border: 2px solid var(--yellow); background: #1d0d38; color: #fff; font-family: var(--mono); font-size: 1rem; }
#stdin input:focus { outline: none; box-shadow: 0 0 0 3px #F3DB5244; }
#stdin button { background: var(--yellow); color: var(--navy); border: 0; border-radius: 8px; padding: .45rem .9rem; font-weight: 800; cursor: pointer; }
#checks { border-top: 1px solid #ffffff1a; padding: .6rem 1rem .8rem; max-height: 38%; overflow: auto; color: #d9ccf0; font-size: .95rem; }
#checks .res { display: flex; gap: .5rem; align-items: baseline; margin: .15rem 0; font-family: var(--mono); font-size: .9rem; }
#checks .ok { color: var(--green); } #checks .bad { color: #ff9e8f; }
#checks .sum { margin-top: .4rem; font-weight: 800; }

/* ============ Motyw i rozmiar czcionki edytora ============ */
.editor-view-controls { display: inline-flex; align-items: center; gap: .35rem; }
.editor-view-controls .btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: .3rem .55rem;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s ease;
  line-height: 1;
}
.editor-view-controls .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.25);
}
.editor-view-controls .btn-ghost.active {
  background: var(--yellow);
  color: var(--navy);
  border-color: var(--yellow);
}
.font-sizes { display: inline-flex; gap: 2px; }
.font-sizes button { min-width: 1.85rem; text-align: center; }

/* Rozmiary czcionki w edytorze */
.workspace.fs-sm .gutter, .workspace.fs-sm #code { font-size: 1rem; line-height: 1.65; }
.workspace.fs-md .gutter, .workspace.fs-md #code { font-size: 1.2rem; line-height: 1.68; }
.workspace.fs-lg .gutter, .workspace.fs-lg #code { font-size: 1.42rem; line-height: 1.72; }

/* Jasny motyw edytora kodu */
.workspace.theme-light { background: #f8f9fa; }
.workspace.theme-light .toolbar { background: #e9ecef; border-bottom: 1px solid #ced4da; }
.workspace.theme-light .toolbar .file { color: #495057; }
.workspace.theme-light .toolbar .save-state { color: #6c757d; }
.workspace.theme-light .editor-view-controls .btn-ghost {
  background: #dee2e6;
  color: #212529;
  border-color: #ced4da;
}
.workspace.theme-light .editor-view-controls .btn-ghost:hover {
  background: #ced4da;
}
.workspace.theme-light .editor-view-controls .btn-ghost.active {
  background: #ffc107;
  color: #000;
  border-color: #ffc107;
}
.workspace.theme-light .gutter { background: #f1f3f5; color: #868e96; border-right: 1px solid #dee2e6; }
.workspace.theme-light #code { background: #ffffff; color: #212529; caret-color: #0d6efd; }
.workspace.theme-light #code:focus { box-shadow: inset 0 0 0 2px #0d6efd44; }
.workspace.theme-light .editor.locked #code { background: #e9ecef; color: #6c757d; }
.workspace.theme-light .privacy { background: #f1f3f5; color: #6c757d; border-top: 1px solid #dee2e6; }
.workspace.theme-light .console { background: #f8f9fa; border-top: 2px solid #dee2e6; }
.workspace.theme-light .console-head { color: #495057; }
.workspace.theme-light .console-head button { color: #6c757d; }
.workspace.theme-light .console-head button:hover { color: #212529; }
.workspace.theme-light #output { color: #157347; background: #ffffff; }
.workspace.theme-light #output .muted { color: #6c757d; }
.workspace.theme-light #output .err { color: #dc3545; }
.workspace.theme-light #output .typed { color: #0d6efd; }
.workspace.theme-light #stdin { background: #f1f3f5; }
.workspace.theme-light #stdin label { color: #212529; }
.workspace.theme-light #stdin input { background: #ffffff; color: #212529; border: 2px solid #0d6efd; }
.workspace.theme-light #checks { border-top: 1px solid #dee2e6; color: #212529; }

/* ============ Responsywność ============ */
@media (max-width: 860px) {
  html, body { height: auto; }
  body { display: block; }
  #app, #app > section { overflow: visible; }
  .topbar { flex-wrap: wrap; padding: .5rem .9rem; gap: .4rem; }
  .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; padding-bottom: 0; }
  .tabs button { padding: .6rem .8rem; white-space: nowrap; }
  .who .who-text { display: none; }
  .work-grid { grid-template-columns: 1fr; }
  #screen-work { overflow: visible; }
  .lesson { border-right: 0; border-bottom: 2px solid var(--line); overflow: visible; }
  .workspace { min-height: 560px; }
  .task .t-meta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
