/* ===== Цвета Системы (тёмно-синий интерфейс как в аниме) ===== */
:root {
  --bg: #05070f;
  --panel: rgba(9, 18, 40, 0.88);
  --line: #39b8ff;
  --glow: rgba(57, 184, 255, 0.45);
  --text: #dceaff;
  --muted: #8ea6c8;
  --accent: #6fd0ff;
  --gold: #ffcf5a;
  --red: #ff4d5e;
  --red-glow: rgba(255, 77, 94, 0.5);
  --green: #5cf2a5;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* иначе display:grid у форм перебивает hidden */

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

body {
  background: var(--bg);
  /* лёгкое свечение «портала» на фоне */
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(57, 120, 255, 0.25), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(100, 60, 255, 0.18), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Exo 2", system-ui, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

.screen { display: none; animation: appear .25s ease; }
.screen.active { display: block; }

@keyframes appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Окно Системы: рамка со свечением ===== */
.window {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 0 14px var(--glow), inset 0 0 18px rgba(57, 184, 255, 0.12);
  padding: 18px 16px 16px;
  margin: 22px 0;
}

.window-title {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 2px 14px;
  font-family: "Russo One", sans-serif;
  font-size: 13px;
  letter-spacing: 2px;
  white-space: nowrap;
  color: var(--accent);
  box-shadow: 0 0 10px var(--glow);
}

.muted { color: var(--muted); }
.small-text { font-size: 14px; }

/* ===== Статус ===== */
.status-head { display: flex; gap: 16px; align-items: center; }

.level-box { text-align: center; min-width: 84px; }
.level-num {
  font-family: "Russo One", sans-serif;
  font-size: 52px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 12px var(--line);
}
.level-label { font-size: 12px; letter-spacing: 2px; color: var(--muted); margin-top: 4px; }

.status-info { display: grid; gap: 4px; font-size: 15px; }
.status-info .k { color: var(--muted); font-size: 13px; letter-spacing: 1px; }

.rank {
  font-family: "Russo One", sans-serif;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 207, 90, .6);
}

.xp { margin-top: 16px; }
.xp-bar {
  height: 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
  background: rgba(57, 184, 255, 0.08);
}
.xp-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #2a7dff, var(--accent));
  box-shadow: 0 0 10px var(--line);
  transition: width .5s ease;
}
.xp-text { text-align: right; font-size: 13px; color: var(--muted); margin-top: 4px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid rgba(57, 184, 255, .35);
  border-radius: 4px;
  padding: 8px 10px;
}
.stat-name { font-size: 13px; color: var(--muted); }
.stat-name b { display: block; color: var(--text); font-size: 15px; letter-spacing: 1px; }
.stat-val { font-family: "Russo One", sans-serif; font-size: 22px; }
.stat-plus {
  margin-left: 8px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  font-size: 18px;
  cursor: pointer;
}
.free-points { margin-top: 12px; text-align: center; color: var(--gold); min-height: 1em; }

.today-line { font-size: 15px; }
.timer { font-variant-numeric: tabular-nums; color: var(--accent); }

/* ===== Квесты ===== */
.quest-sub { margin: 4px 0 12px; text-align: center; color: var(--muted); font-size: 14px; }
.quest-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.quest {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(57, 184, 255, .3);
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background .2s, border-color .2s;
}
.quest:hover { background: rgba(57, 184, 255, .07); }
.quest.done { border-color: rgba(92, 242, 165, .5); }
.quest.done .q-title { color: var(--muted); text-decoration: line-through; }

.check {
  flex: none;
  width: 24px; height: 24px;
  border: 2px solid var(--line);
  border-radius: 3px;
  display: grid; place-items: center;
  color: var(--bg);
  font-weight: 800;
}
.quest.done .check { background: var(--green); border-color: var(--green); }

.q-body { flex: 1; min-width: 0; }
.q-title { font-size: 15px; overflow-wrap: anywhere; }
.q-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.q-rank { font-family: "Russo One", sans-serif; color: var(--gold); }

.q-del {
  flex: none;
  background: none; border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
}

.warning { color: var(--red); font-size: 14px; margin: 14px 0 4px; }
.timer-row { text-align: right; font-size: 14px; color: var(--muted); }

/* ===== Формы и кнопки ===== */
.add-form { display: grid; gap: 8px; margin-bottom: 14px; }
.add-row { display: flex; gap: 8px; }
.add-row select { flex: 1; min-width: 0; }

input[type="text"], select {
  width: 100%;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(57, 184, 255, .5);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px — чтобы iPhone не зумил при фокусе */
  padding: 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }

input[type="time"] {
  width: 100%;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(57, 184, 255, .5);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 10px;
  color-scheme: dark;
}
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 4px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--line); }

.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(57, 184, 255, .12);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}
.btn:hover { background: rgba(57, 184, 255, .22); }
.btn.danger { border-color: var(--red); background: rgba(255, 77, 94, .12); color: #ffd6da; }
.btn.danger:hover { background: rgba(255, 77, 94, .22); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.btn-row .btn { flex: 1; }
#btn-reset { width: 100%; }

.edit-list { list-style: none; padding: 0; margin: 10px 0 14px; display: grid; gap: 6px; }
.edit-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(57, 184, 255, .25);
  border-radius: 4px;
  font-size: 15px;
}
.edit-list li span { flex: 1; }

/* ===== Рейтинг ===== */
.top-me { font-size: 15px; }
.top-msg { min-height: 1.2em; margin: 6px 0; color: var(--muted); }
.top-msg.bad { color: var(--red); }
.link {
  background: none; border: none; padding: 0 4px;
  color: var(--muted); font: inherit; font-size: 14px;
  text-decoration: underline; cursor: pointer;
}

.link-details { margin: 4px 0 8px; }
.link-details summary { cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 0; }
.link-details .add-form { margin: 8px 0 0; }
.link-btn { width: 100%; margin-top: 10px; white-space: normal; }
.link-box { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 4px; text-align: center; }
.link-code {
  font-family: "Russo One", monospace;
  font-size: 34px;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 12px var(--line);
  margin: 8px 0;
  user-select: all;
}
#link-code { text-transform: uppercase; letter-spacing: 3px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; margin: 8px 0 12px; }
.seg button {
  flex: 1;
  background: none; border: none;
  color: var(--muted); font: inherit; font-size: 14px;
  padding: 8px; cursor: pointer;
}
.seg button.active { background: rgba(57, 184, 255, .2); color: var(--text); }

.top-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.top-row {
  display: grid;
  grid-template-columns: 34px 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(57, 184, 255, .25);
  border-radius: 4px;
}
.top-row.me { border-color: var(--gold); box-shadow: 0 0 10px rgba(255, 207, 90, .3); }
.top-place { font-family: "Russo One", sans-serif; color: var(--muted); text-align: center; }
.top-row:nth-child(1) .top-place { color: var(--gold); }
.top-row:nth-child(2) .top-place { color: #d6e2f0; }
.top-row:nth-child(3) .top-place { color: #e0a070; }
.top-nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-nick small { display: block; color: var(--muted); font-size: 12px; }
.top-val { font-family: "Russo One", sans-serif; font-size: 15px; text-align: right; }
.top-refresh { width: 100%; margin-top: 12px; }

/* ===== Журнал ===== */
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.log li { border-left: 2px solid var(--line); padding: 4px 10px; }
.log li.bad { border-color: var(--red); }
.log li.good { border-color: var(--gold); }
.log time { display: block; font-size: 12px; color: var(--muted); }

/* ===== Нижняя панель ===== */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  background: rgba(5, 7, 15, .92);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(57, 184, 255, .4);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  position: relative;
  flex: 1;
  max-width: 140px;
  height: var(--tabbar-h);
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer;
}
.tab .ic { font-size: 20px; }
.tab.active { color: var(--accent); text-shadow: 0 0 8px var(--glow); }
.badge {
  position: absolute;
  top: 8px; right: calc(50% - 22px);
  min-width: 18px; height: 18px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: grid; place-items: center;
  padding: 0 5px;
}

/* ===== Уведомления ===== */
.toasts {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 420px);
  display: grid; gap: 8px;
  z-index: 30;
  pointer-events: none;
}
.toast {
  background: rgba(5, 12, 30, .95);
  border: 1px solid var(--line);
  box-shadow: 0 0 16px var(--glow);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 14px;
  animation: toast-in .3s ease, toast-out .4s ease 2.8s forwards;
}
.toast b { color: var(--accent); font-family: "Russo One", sans-serif; font-weight: 400; letter-spacing: 1px; }
.toast.gold { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 207, 90, .45); }
.toast.bad { border-color: var(--red); box-shadow: 0 0 16px var(--red-glow); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ===== Модалка ===== */
.modal, .penalty {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .7);
  z-index: 20;
}
.modal[hidden], .penalty[hidden] { display: none; }
.modal-window { width: min(100%, 420px); margin: 0; background: #08122a; animation: appear .25s ease; }
#modal-body { line-height: 1.5; }
#modal-body .big {
  text-align: center;
  font-family: "Russo One", sans-serif;
  font-size: 40px;
  color: #fff;
  text-shadow: 0 0 14px var(--line);
  margin: 8px 0;
}

/* ===== Штрафная зона: всё красное ===== */
.penalty {
  z-index: 25;
  background: radial-gradient(ellipse at center, rgba(90, 0, 10, .85), rgba(0, 0, 0, .96));
}
.penalty-window {
  width: min(100%, 420px);
  margin: 0;
  border-color: var(--red);
  box-shadow: 0 0 24px var(--red-glow), inset 0 0 20px rgba(255, 77, 94, .15);
  animation: pulse 2s ease-in-out infinite;
}
.penalty-window .window-title { color: var(--red); border-color: var(--red); box-shadow: 0 0 10px var(--red-glow); }
.penalty-task {
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  margin: 16px 0;
  color: #fff;
}
@keyframes pulse { 50% { box-shadow: 0 0 40px var(--red-glow), inset 0 0 26px rgba(255, 77, 94, .25); } }

/* Кнопка «удерживай»: полоска заполняется, пока держишь палец */
.btn.hold { width: 100%; padding: 14px; touch-action: none; user-select: none; -webkit-user-select: none; }
.hold-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0;
  background: rgba(255, 77, 94, .45);
}
.hold-text { position: relative; }

/* Кто отключил анимации в системе — тому без анимаций */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
