:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f0ece5;
  --text: #1d1b19;
  --muted: #6b655d;
  --line: #e2dcd2;
  --accent: #c2502b;
  --accent-text: #ffffff;
  --focus: #2f6fdb;
  --error: #b3261e;
  --shadow: 0 10px 40px rgba(20, 16, 10, 0.18);
  --radius: 18px;
  --cam-ui: rgba(17, 18, 20, 0.62);
  --cam-text: #f5f3ef;
  --seg-on: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #151413;
    --surface: #1f1d1b;
    --surface-2: #2a2725;
    --text: #f1ede7;
    --muted: #a59d93;
    --line: #38342f;
    --accent: #e0714a;
    --accent-text: #1a0d07;
    --focus: #7aa7ff;
    --error: #ff8a80;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --seg-on: #4a4540;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #151413;
  --surface: #1f1d1b;
  --surface-2: #2a2725;
  --text: #f1ede7;
  --muted: #a59d93;
  --line: #38342f;
  --accent: #e0714a;
  --accent-text: #1a0d07;
  --focus: #7aa7ff;
  --error: #ff8a80;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  --seg-on: #4a4540;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button,
input,
label.btn {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Przyciski ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  text-align: center;
  user-select: none;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn.ghost {
  background: transparent;
  color: inherit;
  border-color: currentColor;
  border-color: color-mix(in srgb, currentColor 35%, transparent);
}

.btn.small {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 14px;
}

.btn.big {
  min-height: 54px;
  padding: 14px 28px;
  font-size: 18px;
}

.btn.wide {
  width: 100%;
}

.btn:active {
  transform: translateY(1px);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background: var(--cam-ui);
  color: var(--cam-text);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  flex: none;
}

.icon-btn.plain {
  background: var(--surface-2);
  color: var(--text);
}

/* --- Ekran startowy ----------------------------------------------------- */

.screen {
  position: fixed;
  inset: 0;
}

.start {
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.start-inner {
  width: 100%;
  max-width: 460px;
  text-align: center;
}

.logo {
  position: relative;
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
}

.logo span {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.logo span:first-child {
  left: 0;
  top: 0;
  background: #e2a03f;
}

.logo span:last-child {
  right: 0;
  bottom: 0;
  background: #4b3f7a;
  mix-blend-mode: multiply;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 7vw, 38px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 17px;
}

.alt {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

.error {
  color: var(--error);
  margin: 18px 0 0;
}

.fine {
  margin-top: 28px;
  color: var(--muted);
  font-size: 13px;
}

/* --- Podgląd z aparatu -------------------------------------------------- */

.viewer {
  background: #000;
  color: var(--cam-text);
  overflow: hidden;
  touch-action: none;
}

.viewer video,
.viewer img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewer img {
  object-fit: contain;
}

/* Okrąg celownika ma promień 18 px: dokładnie z tego koła brana jest próbka koloru. */
.reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 80px;
  height: 80px;
  margin: -40px 0 0 -40px;
  pointer-events: none;
}

.reticle svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.reticle .outline {
  stroke: rgba(0, 0, 0, 0.7);
  stroke-width: 5;
}

.reticle .main {
  stroke: #fff;
  stroke-width: 2;
}

.topbar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}

.hint {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--cam-ui);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint.calib {
  background: #f2c230;
  color: #1d1b19;
  white-space: normal;
}

.bottombar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
}

.live {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 auto 14px;
  max-width: 420px;
}

.live-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 8px 12px 8px 8px;
  border-radius: 16px;
  background: var(--cam-ui);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.live-chip b {
  display: block;
  font-size: 13px;
}

.live-chip small {
  display: block;
  font-size: 12px;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

.live-arrow {
  flex: none;
  opacity: 0.85;
}

.sw {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #555;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
}

.actions .btn.ghost {
  color: var(--cam-text);
  background: var(--cam-ui);
}

.shutter {
  flex: 1;
  min-height: 56px;
  font-size: 18px;
}

/* --- Wynik --------------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(0, 0, 0, 0.45);
  padding-top: 40px;
  z-index: 5;
}

.sheet-inner {
  max-width: 600px;
  min-height: calc(100% - 40px);
  margin: 0 auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 24px);
  box-shadow: var(--shadow);
  animation: rise 0.22s ease-out;
}

@keyframes rise {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sheet-inner {
    animation: none;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  margin-bottom: 16px;
}

.pair-sw {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.sw-big {
  display: block;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  margin-bottom: 4px;
}

.pair-sw small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.sphere {
  position: relative;
  width: clamp(76px, 24vw, 130px);
  aspect-ratio: 1;
  margin-top: 6px;
}

.sphere::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, var(--base) 0 26%, var(--shadow-c) 78%);
  z-index: 1;
}

.sphere .cast {
  position: absolute;
  left: 26%;
  right: -4%;
  bottom: -6%;
  height: 26%;
  border-radius: 50%;
  background: var(--cast, #444);
  filter: blur(4px);
  opacity: 0.85;
}

.controls {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.control-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.seg button {
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  line-height: 1.2;
}

.seg button small {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.seg button[aria-checked='true'] {
  background: var(--seg-on);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  font-weight: 700;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.card-sub {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.theory {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.theory li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 15px;
}

.theory .dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.theory .num {
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  background: var(--surface-2);
}

.recipes {
  display: grid;
  gap: 12px;
}

.busy {
  color: var(--muted);
  margin: 0;
}

.recipe {
  border-radius: 14px;
  background: var(--surface-2);
  padding: 12px;
}

.recipe-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.recipe-head .sw-res {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.recipe-head b {
  display: block;
  font-size: 15px;
}

.recipe-head small {
  color: var(--muted);
  font-size: 13px;
}

.bar {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.bar span {
  display: block;
  height: 100%;
}

.ingredients {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.ingredients li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
}

.paint-sw {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.ingredients .name {
  min-width: 0;
  font-size: 15px;
  line-height: 1.25;
}

.ingredients .name small {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
}

.ingredients .parts {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ingredients .parts small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}

details.more {
  margin-top: 2px;
}

details.more summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}

details.more .recipes {
  margin-top: 6px;
}

.tips ul {
  margin: 8px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  font-size: 15px;
}

/* --- Ustawienia ------------------------------------------------------------ */

.dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog-inner {
  padding: 18px 16px 20px;
}

.paint-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.paint-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
}

.paint-list label {
  display: grid;
  grid-template-columns: 22px 30px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 14.5px;
  line-height: 1.2;
}

.paint-list small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.paint-list input,
.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.paint-list .paint-sw {
  width: 30px;
  height: 30px;
}

.toggle {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: start;
  margin-bottom: 14px;
  cursor: pointer;
}

.toggle small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.wb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 150px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #1d1b19;
  color: #f5f3ef;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 20;
  text-align: center;
}

@media (min-width: 720px) {
  .sheet {
    padding-top: 6vh;
  }

  .sheet-inner {
    border-radius: 22px;
    min-height: 0;
    margin-bottom: 6vh;
    padding: 22px 24px 26px;
  }
}
