/* ==========================================================================
   PePe OS — strona jako retro system operacyjny (pulpit, okna, pasek zadań).
   Kolory jak w style.css (te same zmienne); grafika pikselowa z tools/build-pixel-art.mjs.
   Po zmianie podbij ?v=N przy os.css w index.html.
   ========================================================================== */

:root {
  --bg:        #0c0b10;
  --surface:   #15131c;
  --surface-2: #1d1a26;
  --line:      #2a2633;
  --hi:        #4a4458;   /* jasna krawędź „wypukłości” */
  --edge:      #050407;
  --text:      #ecebf2;
  --muted:     #9b97a8;
  --p1:        #7cf29a;
  --p1-ink:    #07210f;
  --p1-deep:   #2f7a48;
  --p2:        #ff7aa8;
  --gold:      #ffd34d;
  --bar:       44px;      /* wysokość paska zadań */
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body.os {
  margin: 0; overflow: hidden;
  font: 15px/1.5 var(--sans); color: var(--text);
  background: var(--bg);
  cursor: url("/img/cursor.svg") 0 0, auto;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
}
img { display: block; }
.pixel { image-rendering: pixelated; }
a, button { cursor: url("/img/cursor-link.svg") 0 0, pointer; }
a { color: var(--p1); }
:focus-visible { outline: 2px dotted var(--p1); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Delikatne linie CRT tylko na tapecie (nad canvasem z bg.js, pod oknami) – gry w oknach są bez nich. */
body.os::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: repeating-linear-gradient(transparent 0 2px, rgba(0, 0, 0, .14) 2px 3px);
}

/* „Wypukła” i „wklęsła” ramka w stylu starych systemów. */
.raised { box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi); }
.sunken { box-shadow: inset 2px 2px 0 var(--edge), inset -2px -2px 0 var(--hi); }

/* --- Pulpit i ikony --------------------------------------------------------- */
.desktop { position: fixed; inset: 0 0 var(--bar) 0; }
.icons {
  list-style: none; margin: 0; padding: 14px 10px;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(auto-fill, 104px);
  grid-auto-columns: 100px; gap: 6px 8px; height: 100%; align-content: start;
}
.icon {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: 100px; padding: 8px 4px 6px; text-decoration: none; color: var(--text);
  font: 13px/1.25 var(--mono); text-align: center;
  border: 1px dotted transparent;
}
.icon img { width: 48px; height: 48px; filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, .6)); }
.icon span { padding: 1px 4px; text-shadow: 1px 1px 0 var(--edge); overflow-wrap: anywhere; }
.icon:focus-visible { outline: none; border-color: var(--p1); }
.icon.selected span { background: var(--p1-deep); text-shadow: none; }
.icon.selected img { filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, .6)) brightness(.8) sepia(1) hue-rotate(70deg) saturate(2); }
.hint {
  position: absolute; right: 18px; bottom: 14px; margin: 0;
  font: 12px var(--mono); color: var(--muted); text-shadow: 1px 1px 0 var(--edge);
}

/* Treść okien przed przeniesieniem przez os.js (bez JS ikony są zwykłymi linkami do gier). */
.sources { display: none; }

/* --- Okna ------------------------------------------------------------------- */
.windows { position: fixed; inset: 0 0 var(--bar) 0; pointer-events: none; }
.win {
  position: absolute; display: flex; flex-direction: column; pointer-events: auto;
  min-width: 260px; min-height: 160px;
  background: var(--surface); padding: 3px;
  box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi), 6px 6px 0 rgba(0, 0, 0, .45);
}
.win[hidden] { display: none; }
.win.opening { animation: win-open .18s steps(4) both; }
@keyframes win-open { from { transform: scale(.6); opacity: 0; } }
.win.max { inset: 0 !important; width: auto !important; height: auto !important; box-shadow: none; }

.titlebar {
  display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 3px 0 6px; flex: none;
  background: var(--line); color: var(--muted);
  font: 700 13px/1 var(--mono); touch-action: none;
}
.win.active .titlebar { background: linear-gradient(90deg, var(--p1-deep), #1f5a35 60%, var(--surface-2)); color: var(--text); }
.titlebar img { width: 16px; height: 16px; flex: none; }
.titlebar .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wbtn {
  width: 22px; height: 20px; padding: 0; border: 0; flex: none;
  background: var(--surface-2); color: var(--text);
  box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi);
  display: grid; place-items: center;
}
.wbtn:active { box-shadow: inset 2px 2px 0 var(--edge), inset -2px -2px 0 var(--hi); }
.wbtn svg { width: 10px; height: 10px; }
.wbtn.close:hover { background: #8a2a45; }

.menubar {
  display: flex; gap: 2px; flex: none; padding: 2px 2px 3px;
  font: 12px var(--mono);
}
.menubar button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; border: 0; background: none; color: var(--text); font: inherit;
}
.menubar button:hover { background: var(--surface-2); box-shadow: inset -1px -1px 0 var(--edge), inset 1px 1px 0 var(--hi); }
.menubar button[aria-pressed="true"] { color: var(--p1); }
.menubar svg { width: 14px; height: 14px; }
.menubar .spacer { flex: 1; }

.body { position: relative; flex: 1; min-height: 0; background: #17121c; box-shadow: inset 2px 2px 0 var(--edge), inset -2px -2px 0 var(--hi); padding: 2px; }
.body iframe { display: block; width: 100%; height: 100%; border: 0; background: #000; }
.body .doc { height: 100%; overflow: auto; padding: 20px 22px; user-select: text; -webkit-user-select: text; background: var(--bg); font-size: 15px; }

.statusbar {
  display: flex; gap: 3px; flex: none; margin-top: 3px; font: 11px/1 var(--mono); color: var(--muted);
}
.statusbar span { padding: 5px 7px; box-shadow: inset 1px 1px 0 var(--edge), inset -1px -1px 0 var(--hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar span:first-child { flex: 1; }

.grip { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, var(--hi) 50% 58%, transparent 58% 70%, var(--hi) 70% 78%, transparent 78%); }
.win.max .grip { display: none; }

/* Podczas przeciągania iframe nie może łapać myszy. */
.dragging iframe { pointer-events: none; }
.dragging, .dragging * { cursor: grabbing !important; }

/* Ekran „ładowania” gry, zanim iframe się wczyta. */
.loading {
  position: absolute; inset: 2px; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: #000; color: var(--muted); font: 13px var(--mono); pointer-events: none;
  transition: opacity .3s;
}
.loading.done { opacity: 0; }
.loading img { width: 64px; height: 64px; }
.loading .bar { width: 160px; height: 14px; padding: 2px; box-shadow: inset 2px 2px 0 var(--edge), inset -2px -2px 0 var(--hi); }
.loading .bar i { display: block; height: 100%; width: 100%; background: repeating-linear-gradient(90deg, var(--p1) 0 8px, transparent 8px 10px); animation: load 1.6s steps(16) infinite; transform-origin: left; }
@keyframes load { from { transform: scaleX(0); } }

/* Treść „About us.txt”. */
.doc h2 { font: 700 1.2rem/1.3 var(--mono); text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 12px; }
.doc p { margin: 0 0 1em; line-height: 1.65; }
.doc .logo { margin-bottom: 6px; }
.doc .muted { color: var(--muted); font-size: 13px; }
.players { display: flex; align-items: end; gap: 18px; margin: 18px 0; font: 12px var(--mono); color: var(--muted); }
.players figure { margin: 0; display: grid; justify-items: center; gap: 6px; }
.players > span { font: 700 20px var(--mono); color: var(--gold); padding-bottom: 28px; }
.hud { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; margin: 0 0 18px; font-family: var(--mono); }
.hud div { padding: 8px 10px; background: var(--surface); box-shadow: inset 1px 1px 0 var(--edge), inset -1px -1px 0 var(--hi); }
.hud dt { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.hud dd { margin: 0; color: var(--p1); }

/* --- Pasek zadań i menu Start ------------------------------------------------ */
.taskbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar); z-index: 900;
  display: flex; align-items: center; gap: 4px; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  background: var(--surface); box-shadow: inset 0 2px 0 var(--hi);
  font: 13px var(--mono);
}
.start, .task {
  display: inline-flex; align-items: center; gap: 7px; height: 100%; padding: 0 10px; border: 0;
  background: var(--surface-2); color: var(--text); font: 700 13px var(--mono);
  box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi);
}
.start[aria-expanded="true"], .task.active { box-shadow: inset 2px 2px 0 var(--edge), inset -2px -2px 0 var(--hi); background: var(--bg); }
.start img { width: 20px; height: 20px; }
.tasks { flex: 1; min-width: 0; display: flex; gap: 4px; height: 100%; overflow: hidden; }
.task { font-weight: 400; max-width: 190px; min-width: 0; }
.task img { width: 18px; height: 18px; flex: none; }
.task span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray { height: 100%; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 6px; color: var(--muted); box-shadow: inset 1px 1px 0 var(--edge), inset -1px -1px 0 var(--hi); }

.startmenu {
  position: fixed; left: 4px; bottom: calc(var(--bar) - 2px); z-index: 950;
  display: flex; min-width: 250px; padding: 3px;
  background: var(--surface); box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi), 6px 6px 0 rgba(0, 0, 0, .45);
  animation: menu .12s steps(3) both;
}
.startmenu[hidden] { display: none; }
@keyframes menu { from { transform: translateY(12px); opacity: 0; } }
.startmenu-side {
  width: 30px; flex: none; display: flex; align-items: end; justify-content: center; padding-bottom: 10px;
  background: linear-gradient(var(--p2), var(--p1-deep));
}
.startmenu-side span { writing-mode: vertical-rl; transform: rotate(180deg); font: 700 18px var(--mono); color: var(--edge); letter-spacing: .08em; }
.startmenu-side b { color: var(--text); }
.startmenu ul { list-style: none; margin: 0; padding: 2px; flex: 1; }
.startmenu li[role="separator"] { height: 0; margin: 4px 2px; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--hi); }
.startmenu button, .startmenu a {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 12px 6px 8px; border: 0;
  background: none; color: var(--text); font: 13px var(--mono); text-align: left; text-decoration: none;
}
.startmenu button:hover, .startmenu a:hover, .startmenu :focus-visible { background: var(--p1-deep); outline: none; }
.startmenu img { width: 24px; height: 24px; }

/* --- Ekran startowy i wyłączenie ------------------------------------------- */
.boot {
  position: fixed; inset: 0; z-index: 990; display: grid; place-content: center; justify-items: center; gap: 10px;
  background: #000; font: 13px var(--mono); color: var(--muted);
  animation: boot-out .4s 2.2s steps(4) forwards; /* bez JS znika sam */
}
.boot.gone { animation: boot-out .25s steps(3) forwards; }
@keyframes boot-out { to { opacity: 0; visibility: hidden; } }
.boot-name { margin: 0; font-weight: 700; color: var(--text); letter-spacing: .1em; }
.boot-name span { color: var(--p1); }
.boot-log { margin: 0; min-height: 6.4em; width: min(340px, 80vw); font: 12px/1.6 var(--mono); color: var(--p1); white-space: pre-wrap; }
.boot-bar { width: min(340px, 80vw); height: 16px; padding: 2px; box-shadow: inset 2px 2px 0 var(--line), inset -2px -2px 0 var(--hi); }
.boot-bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--p1) 0 10px, transparent 10px 13px); animation: load 2s steps(26) both; transform-origin: left; }

.off {
  position: fixed; inset: 0; z-index: 995; display: grid; place-content: center; background: #000;
}
.off[hidden] { display: none; }
.btn {
  padding: 8px 16px; border: 0; background: var(--surface-2); color: var(--text); font: 13px var(--mono);
  box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi);
}

/* --- Telefon: okna zawsze na cały ekran ------------------------------------ */
@media (max-width: 700px) {
  .icons { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); grid-template-rows: none; grid-auto-columns: auto; justify-items: center; }
  .icon { width: 92px; }
  .hint { display: none; }
  .windows .win { inset: 0 !important; width: auto !important; height: auto !important; box-shadow: none; }
  .win .grip, .win .wbtn.maxi { display: none; }
  .task { padding: 0 8px; }
  .task span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .win.opening, .startmenu { animation: none; }
  .off-term span { animation-delay: 0s !important; }
  .boot { animation-delay: .3s; }
  .boot-bar i, .loading .bar i { animation: none; }
}


/* --- Okno „Shut Down” i ekrany: uśpienie, wylogowanie ------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 980; display: grid; place-items: center; padding: 16px;
  /* przyciemnienie „w kratkę” jak w starych systemach */
  background: repeating-conic-gradient(rgba(0, 0, 0, .55) 0 25%, transparent 0 50%) 0 0 / 4px 4px;
}
.modal[hidden] { display: none; }
.win.dialog { position: relative; width: min(420px, 100%); min-height: 0; animation: win-open .15s steps(3) both; }
.dialog-body { display: flex; gap: 16px; padding: 16px 14px 8px; }
.dialog-body > img { width: 48px; height: 48px; flex: none; }
.dialog fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 2px; min-width: 0; }
.dialog legend { padding: 0 0 8px; font: 13px var(--mono); }
.dialog label { display: flex; gap: 10px; align-items: start; padding: 5px 6px; font-size: 13px; line-height: 1.35; }
.dialog label:hover { background: var(--surface-2); }
.dialog label:has(:checked) { background: var(--p1-deep); }
.dialog input { accent-color: var(--p1); margin: 2px 0 0; }
.dialog b { display: block; font-family: var(--mono); }
.dialog label span { color: var(--muted); }
.dialog label:has(:checked) span { color: var(--text); }
.dialog-buttons { display: flex; justify-content: end; gap: 8px; padding: 8px 10px 10px; }
.dialog-buttons .btn { min-width: 84px; }
.btn:active { box-shadow: inset 2px 2px 0 var(--edge), inset -2px -2px 0 var(--hi); }

.sleep { position: fixed; inset: 0; z-index: 995; background: #000; overflow: hidden; cursor: none; }
.sleep[hidden] { display: none; }
/* Logo odbija się od krawędzi: osobne animacje w poziomie i pionie o różnych czasach. */
.bounce-x { position: absolute; inset: 0; animation: bx 7.3s linear infinite alternate; }
.bounce-y { position: absolute; top: 0; left: 0; animation: by 4.9s linear infinite alternate, hue 9s steps(6) infinite; }
@keyframes bx { from { transform: translateX(0); } to { transform: translateX(calc(100vw - 168px)); } }
@keyframes by { from { transform: translateY(0); } to { transform: translateY(calc(100vh - 56px)); } }
@keyframes hue { to { filter: hue-rotate(360deg); } }

.logon {
  position: fixed; inset: 0; z-index: 990; display: grid; place-content: center; justify-items: center; gap: 18px;
  background: radial-gradient(circle at 50% 40%, #1f5a35, var(--bg) 70%); font: 14px var(--mono); color: var(--muted);
}
.logon[hidden] { display: none; }
.logon p { margin: 0; }
.logon-users { display: flex; gap: 18px; }
.user {
  display: grid; justify-items: center; gap: 10px; padding: 18px 22px 14px; border: 0;
  background: var(--surface); color: var(--text); font: 700 13px var(--mono);
  box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi);
}
.user:hover, .user:focus-visible { background: var(--p1-deep); outline: none; }

@media (prefers-reduced-motion: reduce) {
  .bounce-x, .bounce-y { animation: none; }
  .bounce-y { top: 45%; left: calc(50% - 84px); }
  .win.dialog { animation: none; }
}

/* Ekran po wyłączeniu: linie logu pojawiają się po kolei, na końcu miga kursor. */
.off { cursor: url("/img/cursor-link.svg") 0 0, pointer; animation: none; }
.off-term { margin: 0; font: 15px/1.8 var(--mono); color: var(--p1); text-align: left; display: grid; }
.off-term span { opacity: 0; animation: line .01s forwards; }
.off-term span:nth-child(1) { animation-delay: .5s; } .off-term span:nth-child(2) { animation-delay: .9s; }
.off-term span:nth-child(3) { animation-delay: 1.3s; } .off-term span:nth-child(4) { animation-delay: 1.8s; color: var(--text); }
.off-term span:nth-child(5) { animation-delay: 2.3s; color: var(--muted); }
@keyframes line { to { opacity: 1; } }
.cursor { font-style: normal; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Przycisk dźwięków systemu w zasobniku. */
.sfx { display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; background: none; color: var(--muted); }
.sfx svg { width: 16px; height: 16px; }
.sfx:hover, .sfx[aria-pressed="true"] { color: var(--p1); }

/* Ikony ułożone przez os.js (przeciąganie): każda w swojej komórce siatki. */
.icons.free { display: block; position: relative; padding: 0; }
.icons.free > li { position: absolute; transition: left .12s steps(3), top .12s steps(3); }
.icons.free > li.lifted { transition: none; z-index: 5; opacity: .85; }
.icons.free > li.lifted .icon { cursor: grabbing; }

/* Menu pod prawym przyciskiem (ikony, pulpit, okna, pasek zadań). */
.ctxmenu {
  position: fixed; z-index: 970; min-width: 200px; padding: 3px; display: grid;
  background: var(--surface); box-shadow: inset -2px -2px 0 var(--edge), inset 2px 2px 0 var(--hi), 4px 4px 0 rgba(0, 0, 0, .45);
  font: 13px var(--mono);
}
.ctxmenu[hidden] { display: none; }
.ctxmenu button { padding: 6px 14px 6px 22px; border: 0; background: none; color: var(--text); font: inherit; text-align: left; }
.ctxmenu button.bold { font-weight: 700; }
.ctxmenu button:hover:not(:disabled), .ctxmenu button:focus-visible { background: var(--p1-deep); outline: none; }
.ctxmenu button:disabled { color: #5c5868; cursor: default; }
.ctxmenu .sep { display: block; height: 0; margin: 4px 2px; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--hi); }

/* Okno „Properties”. */
.win.props { width: min(380px, 100%); }
.props-body { padding: 14px 16px 6px; font-size: 13px; }
.props-head { display: flex; align-items: center; gap: 14px; }
.props-head img { width: 40px; height: 40px; }
.props-head b { font: 700 14px var(--mono); }
.props-body hr { border: 0; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--hi); margin: 12px 0; }
.props-body dl { display: grid; grid-template-columns: 96px 1fr; gap: 8px 10px; margin: 0; }
.props-body dt { color: var(--muted); font-family: var(--mono); }
.props-body dd { margin: 0; overflow-wrap: anywhere; line-height: 1.45; user-select: text; -webkit-user-select: text; }
