/* Ksarstvo: общие стили. Телефон первым, главная страница героя без прокрутки. */

:root {
  --bg: #0d0b09;
  --device: #15120f;
  --panel: #1b1814;
  --panel-2: #221e19;
  --line: #3a322a;
  --line-soft: #2a241d;
  --text: #ece4d6;
  --muted: #9d9284;
  --brass: #c9a25a;
  --brass-hi: #e8c77d;
  --brass-dim: #7d6236;
  --oled-on: #b8f0b0;
  --danger: #e7917a;
  --ok: #b6d98f;
  --warn: #d9b36a;
  --reserved: 320px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 70% at 50% -12%, #2a2118 0%, rgba(13, 11, 9, 0) 58%),
    var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.page-pet,
body.page-world {
  height: 100dvh;
  overflow: hidden;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--brass-hi);
  text-underline-offset: 3px;
}

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

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

/* ------------------------------------------------------------ устройство */

.device {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  padding:
    max(var(--safe-t), 8px)
    max(env(safe-area-inset-right, 0px), 12px)
    max(var(--safe-b), 10px)
    max(env(safe-area-inset-left, 0px), 12px);
}

.device-scroll {
  height: auto;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  flex: none;
}

.ident {
  flex: 1;
  min-width: 0;
}

.name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--brass-dim);
  vertical-align: 1px;
}

.sub .dot.is-live {
  background: var(--oled-on);
  box-shadow: 0 0 6px rgba(184, 240, 176, 0.6);
}

.sub .dot.is-off {
  background: var(--danger);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--panel-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--brass-hi);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* -------------------------------------------------------- экран героя */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.oled-frame {
  flex: 0 1 auto;
  width: min(100%, max(160px, calc((100dvh - var(--reserved) - var(--safe-t) - var(--safe-b)) * 2)));
  min-width: 0;
  padding: 7px;
  border-radius: 14px;
  background: linear-gradient(180deg, #211d18, #100e0c);
  border: 1px solid #332b22;
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 210, 0.05),
    0 10px 30px rgba(0, 0, 0, 0.45);
  margin-top: 2px;
}

.oled-well {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border-radius: 6px;
  background: #020302;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.9);
}

.oled-well canvas {
  display: block;
  image-rendering: pixelated;
  border-radius: 1px;
  box-shadow: 0 0 22px rgba(184, 240, 176, 0.06);
}

.event {
  width: 100%;
  min-height: 48px;
  padding: 6px 10px;
  border-left: 2px solid var(--brass-dim);
  background: rgba(201, 162, 90, 0.05);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.event.is-dead {
  border-left-color: var(--danger);
  color: var(--danger);
}

.vitals {
  width: 100%;
  display: grid;
  gap: 6px;
}

.vital-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.vital {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.vital b {
  min-width: 2.2em;
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

.bar {
  position: relative;
  display: block;
  height: 6px;
  border-radius: 3px;
  background: #0b0a08;
  border: 1px solid #2f2820;
  overflow: hidden;
}

.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--v, 0%);
  background: linear-gradient(90deg, var(--brass-dim), var(--brass));
  transition: width 0.4s ease-out;
}

.meta {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.keys {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: auto;
}

.key {
  position: relative;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1px;
  min-height: 60px;
  padding: 6px 4px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #40372c;
  background: linear-gradient(180deg, #2a251e 0%, #1c1915 100%);
  box-shadow: inset 0 1px 0 rgba(255, 240, 210, 0.07), 0 3px 0 #090806;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.06s, box-shadow 0.06s;
}

.key-num {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 10px;
  color: var(--brass-dim);
  font-variant-numeric: tabular-nums;
}

.key-name {
  font-size: 14px;
  font-weight: 620;
}

.key-alt {
  font-size: 11px;
  color: var(--brass);
  opacity: 0.85;
}

.key.is-pressed {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 240, 210, 0.04), 0 1px 0 #090806;
  background: #1a1713;
}

.key.is-holding {
  border-color: var(--brass);
}

.key.is-holding::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--brass-hi);
  transform-origin: left;
  animation: hold-fill 700ms linear forwards;
}

.key:disabled,
.key[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
}

.key:disabled .key-alt,
.key[aria-disabled="true"] .key-alt {
  color: var(--muted);
}

.notice {
  min-height: 16px;
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
  color: var(--muted);
  flex: none;
}

.notice.is-warn {
  color: var(--warn);
}

.notice.is-error {
  color: var(--danger);
}

@keyframes hold-fill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* --------------------------------------------------------- страницы */

.page-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  flex: none;
}

.page-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.page-pet .page-main,
.page-world .page-main {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

.card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line-soft);
  background: var(--panel);
}

.card h2 {
  font-size: 15px;
  font-weight: 650;
}

.recovery {
  border-color: var(--warn);
}

.recovery-secret {
  min-height: 52px;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass-dim);
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.lead {
  font-size: 13px;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.grow {
  flex: 1;
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.ok {
  color: var(--ok);
}

.err {
  color: var(--danger);
}

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

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

button.list-item:active {
  background: #29241d;
}

.list-item .grow {
  display: grid;
  gap: 2px;
}

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

.chev {
  color: var(--brass-dim);
  font-size: 18px;
  flex: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 6px;
  background: #0f0d0a;
  border: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tag.up {
  color: var(--ok);
}

.tag.down {
  color: var(--danger);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid #473e32;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: linear-gradient(180deg, #d4aa62, #a5803d);
  border-color: #dcb873;
  color: #1a140c;
}

.btn.danger {
  color: var(--danger);
  border-color: #5a3429;
}

.btn.small {
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
}

.btn.wide {
  width: 100%;
}

.btn.is-armed {
  color: var(--warn);
  border-color: var(--warn);
}

.row > .list-item {
  flex: 1 1 auto;
  min-width: 0;
}

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

.field .opt {
  color: var(--brass-dim);
  font-size: 12px;
}

input[type="text"],
input[type="email"],
input[type="number"],
input:not([type]),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #3c3429;
  background: #0f0d0a;
  color: var(--text);
  font-size: 16px;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #6f655a;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(201, 162, 90, 0.18);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  color: var(--brass-hi);
  border-color: var(--brass-dim);
  background: #2a2319;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
}

.switch input {
  width: 22px;
  height: 22px;
  accent-color: var(--brass);
}

.code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 26px;
  letter-spacing: 0.18em;
  color: var(--oled-on);
  text-align: center;
  padding: 10px;
  border-radius: 12px;
  background: #020302;
  border: 1px solid #22301f;
}

pre.raw {
  margin: 0;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  border-radius: 10px;
  background: #0a0908;
  border: 1px solid var(--line-soft);
  font: 12px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.empty {
  padding: 18px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.skeleton {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #211d18, #2b261f, #211d18);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ----------------------------------------------------- шторки/диалоги */

dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: min(100%, 460px);
  max-width: 100%;
  max-height: min(84dvh, 720px);
  padding: 0;
  border: 1px solid #3c3429;
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: #171410;
  color: var(--text);
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
}

/* Закрытые шторки не должны рисоваться: авторский display:flex выше перебивает UA-правило dialog:not([open]). */
dialog.sheet:not([open]) {
  display: none;
}

dialog.sheet[open] {
  animation: sheet-in 200ms ease-out;
}

dialog.sheet::backdrop {
  background: rgba(3, 2, 1, 0.66);
}

.sheet-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 16px 12px 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.sheet-head::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 50%;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 2px;
  background: #4a4136;
}

.sheet-head h2 {
  flex: 1;
  font-size: 16px;
  font-weight: 650;
}

.sheet-body {
  display: grid;
  gap: 12px;
  min-height: 0;
  padding: 12px 14px calc(14px + var(--safe-b));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sheet-body .foot {
  font-size: 12px;
  color: var(--muted);
}

@keyframes sheet-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.toasts {
  position: fixed;
  top: calc(var(--safe-t) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: grid;
  gap: 6px;
  width: min(92vw, 380px);
  pointer-events: none;
}

.toast {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #4a3f30;
  background: #2a241d;
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toast-in 180ms ease-out;
}

.toast-warn {
  border-color: #8a6a2e;
}

.toast-error {
  border-color: #6a3a2e;
  color: #f2b1a0;
}

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

.diary {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
}

.entry {
  display: grid;
  gap: 4px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line-soft);
}

.entry:last-child {
  border-bottom: 0;
}

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.entry-meta a {
  color: var(--brass);
}

.entry-meta time {
  font-variant-numeric: tabular-nums;
}

.entry-text {
  font-size: 14px;
  line-height: 1.4;
}

.list-item .grow.pair {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
}

.list-item .grow.pair small {
  font-size: 12px;
}

/* ------------------------------------------------------ большие экраны */

@media (min-width: 640px) and (min-height: 760px) {
  body.page-pet,
  body.page-world {
    padding: 24px 0;
    box-sizing: border-box;
  }

  .device {
    height: min(calc(100dvh - 48px), 860px);
    padding: 22px 20px 20px;
    border-radius: 44px;
    background: var(--device);
    border: 1px solid #2c261e;
    box-shadow:
      0 0 0 9px #0b0a08,
      0 0 0 10px #2c261e,
      0 40px 90px rgba(0, 0, 0, 0.7);
  }
}

@media (max-width: 359px) {
  .keys {
    gap: 6px;
  }

  .key-alt {
    font-size: 10px;
  }
}

/* Низкий экран: плотнее по вертикали, документ по-прежнему не прокручивается. */
@media (max-height: 599px) {
  .stage {
    gap: 6px;
  }

  .event {
    min-height: 40px;
  }

  .key {
    min-height: 52px;
  }
}

/* Совсем низкий экран (ландшафт телефона): последнее средство — прокрутка внутри .stage, body фиксирован. */
@media (max-height: 459px) {
  .stage {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
