:root {
  --bg: #1c1c1e;
  --panel: #2c2c2e;
  --text: #f5f5f7;
  --muted: #9a9aa0;
  --accent: #ff9f0a;
  --danger: #ff453a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px);
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- */
/* Личина: калькулятор                                               */
/* ---------------------------------------------------------------- */

.skin-calc { justify-content: flex-end; }
.calc-top { flex: 1; }

.calc-display {
  text-align: right;
  font-size: clamp(48px, 16vw, 84px);
  font-weight: 300;
  padding: 8px 8px 20px;
  overflow-x: auto;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding-bottom: 8px;
}

.calc-key {
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 999px;
  background: #333336;
  font-size: clamp(22px, 7vw, 30px);
  cursor: pointer;
  transition: filter .12s;
}
.calc-key:active { filter: brightness(1.5); }
.calc-key.op { background: #4a4a4f; }
.calc-key.accent { background: var(--accent); color: #fff; }
.calc-key.wide { aspect-ratio: auto; grid-column: span 2; border-radius: 999px; }

/* ---------------------------------------------------------------- */
/* Личины: общее                                                     */
/* ---------------------------------------------------------------- */

.skin-head { padding: 18px 4px 6px; }
.skin-head h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }

.skin-search {
  width: 100%;
  padding: 11px 14px;
  margin: 8px 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  outline: none;
}
.skin-search:focus { box-shadow: 0 0 0 2px #48484d inset; }

.skin-notes, .skin-weather, .skin-converter { overflow-y: auto; }

.note-list { display: flex; flex-direction: column; gap: 10px; }
.note { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; }
.note-title { font-weight: 600; margin-bottom: 3px; }
.note-body { color: var(--muted); font-size: 14px; }

.skin-weather { background: #0f1b2b; }
.wx-hero { text-align: center; padding: 26px 0 18px; }
.wx-city { font-size: 22px; color: var(--muted); }
.wx-temp { font-size: 76px; font-weight: 200; line-height: 1.05; }
.wx-desc { color: var(--muted); }
.wx-days { display: flex; flex-direction: column; gap: 2px; }
.wx-day {
  display: grid;
  grid-template-columns: 46px 40px 1fr;
  align-items: center;
  padding: 11px 6px;
  border-top: 1px solid #ffffff14;
}
.wx-range { text-align: right; color: var(--muted); }

.skin-converter { background: #14181c; }
.conv-kind, .conv-unit {
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
}
.conv-kind { width: 100%; margin-bottom: 10px; }
.conv-input { font-size: 26px; text-align: right; }
.conv-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.conv-arrow { color: var(--muted); }
.conv-out {
  margin-top: 18px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 18px 12px;
}
.conv-result {
  font-size: 44px;
  font-weight: 300;
  text-align: right;
  word-break: break-all;
  line-height: 1.1;
}
.conv-out-unit { text-align: right; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- */
/* Вход                                                              */
/* ---------------------------------------------------------------- */

.auth { justify-content: center; align-items: center; background: #101012; }
.auth-box { width: min(380px, 100%); display: flex; flex-direction: column; gap: 6px; }
.auth-box h2 { margin: 0 0 10px; font-size: 22px; }
.auth-box label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.auth-box input {
  padding: 12px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  outline: none;
}
.auth-box input:focus { box-shadow: 0 0 0 2px #48484d inset; }
.auth-row { display: flex; gap: 10px; }
.auth-row .btn { flex: 1; }
.auth-error { color: var(--danger); min-height: 20px; font-size: 14px; margin: 6px 0 0; }
.auth-note { color: var(--muted); font-size: 12px; margin-top: 14px; }

.btn {
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  margin-top: 8px;
}
.btn.primary { background: var(--accent); color: #1a1a1a; font-weight: 600; }
.btn.ghost { background: #2a2a2d; color: var(--muted); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:active { filter: brightness(.9); }

/* ---------------------------------------------------------------- */
/* Хранилище                                                         */
/* ---------------------------------------------------------------- */

.vault { padding: 0; }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: #101012;
  border-bottom: 1px solid #ffffff12;
}
.bar-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-stats { color: var(--muted); font-size: 12px; }

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 19px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
  text-decoration: none;
  line-height: 1;
}
.icon-btn:active { background: #ffffff1a; }

.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  padding: 12px;
  align-content: start;
}

.cell {
  border: 0;
  padding: 0;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}
.cell.broken { opacity: .45; }
.cell-media {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  background: #3a3a3d;
}
.cell-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell-name {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty { color: var(--muted); text-align: center; padding: 30px 24px; margin: 0; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 30px;
  cursor: pointer;
  box-shadow: 0 6px 18px #0009;
}

/* ---------------------------------------------------------------- */
/* Просмотр и модальные окна                                         */
/* ---------------------------------------------------------------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  display: flex;
  flex-direction: column;
}
.viewer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: auto;
}
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-file { color: var(--muted); text-align: center; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000000b0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  width: min(380px, 100%);
  background: #1e1e21;
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 8px; }
.modal-box label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.modal-box select, .modal-box input {
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  outline: none;
}
.modal-box hr { border: 0; border-top: 1px solid #ffffff14; margin: 16px 0 4px; width: 100%; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.busy {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000000c0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.busy-box { display: flex; align-items: center; gap: 12px; }
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid #ffffff40;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}
