/* CLODIA на телефоні: горизонтальний екран, керування пальцями. Усе тут діє лише під класом touch на <html>
   (його ставить рядок у <head> index.html); на комп'ютері цей файл нічого не змінює.
   Розміри, як і всюди, множаться на --k — на телефоні його рахує touch.js із висоти екрана (0.72…1).
   Розкладка: ліворуч унизу джойстик, поруч згорнутий чат; праворуч унизу панель дій 2×6 і чотири кнопки дій;
   угорі — рамка героя, ціль, кнопки чату, рюкзака й меню, мінікарта. Вікна стоять на місцях і вміщаються у висоту екрана. */

html.touch {
  --sl: max(8px, env(safe-area-inset-left)); --sr: max(8px, env(safe-area-inset-right)); --st: max(6px, env(safe-area-inset-top)); --sb: max(6px, env(safe-area-inset-bottom));
  --slot: max(40px, calc(46px * var(--k)));          /* слот рюкзака — не менший за палець */
  --hs: max(40px, calc(48px * var(--k)));            /* слот панелі дій і кнопка дії */
  --joy: calc(116px * var(--k));
  --invw: max(304px, calc(338px * var(--k)));        /* ширина рюкзака: шість слотів мають уміститися */
  --mini: 108px;
  font-size: max(11.5px, calc(13px * var(--k)));
  touch-action: none; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
html.touch body { position: fixed; inset: 0; width: 100%; touch-action: none; overscroll-behavior: none; }
html.touch, html.touch * { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
html.touch input { -webkit-user-select: text; user-select: text; font-size: 16px; touch-action: manipulation; }   /* 16px: iPhone не наближає сторінку, коли поле в роботі */
html.touch input[type=range] { touch-action: none; }
html.touch #c, html.touch #joy, html.touch #tbtns, html.touch #hotbar, html.touch #tquick { touch-action: none; }
html.touch .win .body, html.touch .side, html.touch #chatLog, html.touch .overlay, html.touch #tooltip.touch, html.touch .wleg, html.touch #menu { touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
html.touch *::-webkit-scrollbar { width: 5px; height: 5px; }
/* «Наведення» на сенсорному екрані залипає на останньому дотику — підсвічування лишається тільки на час натиску. */
html.touch .slot:hover { filter: none; } html.touch .slot:hover::after { opacity: 0; }
html.touch .slot.off:hover { filter: grayscale(1) brightness(.5); }
html.touch .slot:active { filter: brightness(1.3); }
html.touch .slot .key, html.touch .mapBtn, html.touch #mapNorth { display: none; }
html.touch .btn { min-height: 38px; }
html.touch .btn.sm { min-height: 36px; min-width: 46px; padding: .18em .8em; }
html.touch .tab { min-height: 36px; padding: .3em 1em; }
html.touch .invbar .tab { padding: .3em .2em; }

/* ── Рамки вгорі ── */
html.touch #me { left: var(--sl); top: var(--st); width: calc(232px * var(--k)); height: calc(58px * var(--k)); padding: 0 9px 0 calc(62px * var(--k)); }
html.touch .medal { width: calc(64px * var(--k)); height: calc(64px * var(--k)); }
html.touch #meName, html.touch #tgName { font-size: 1.05rem; }
html.touch .bar { height: 1.1rem; } html.touch .bar.mp { height: .95rem; } html.touch .bar.thin { height: .45rem; }
html.touch #status { left: var(--sl); top: calc(var(--st) + 66px * var(--k)); width: calc(250px * var(--k)); }
html.touch #sub { margin-bottom: 3px; }
html.touch .subBadge { height: 1.7em; }
html.touch #party { margin-top: 5px; width: auto; align-items: flex-start; gap: 3px; }
html.touch .pm { width: calc(190px * var(--k)); padding: 3px 7px 4px 4px; }
html.touch .pm .kick { width: 26px; height: 26px; }
html.touch .pfoot .ploot { height: 36px; }
html.touch #target { top: var(--st); width: calc(250px * var(--k)); padding: 5px 9px 7px; }
html.touch .tghead { margin-bottom: 2px; }
html.touch #tgBtns { gap: 4px; margin-top: 5px; }
html.touch #tgBtns .btn.sm { min-width: 0; padding: .18em .5em; }

/* ── Мінікарта: те саме полотно, зменшене; дотик відкриває карту світу ── */
html.touch #right { right: var(--sr); top: var(--st); width: var(--mini); }
html.touch #mapBox { transform: scale(.48); transform-origin: top right; margin: 0 0 -116px -116px; }
html.touch #zoneName { margin-top: 5px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.touch #mapCoords { font-size: 10px; }
html.touch #tracker { width: 168px; margin: 5px 0 0 -60px; padding: 5px 7px 1px 9px; font-size: 11px; line-height: 1.3; pointer-events: none; overflow: hidden;
  max-height: calc(100vh - var(--st) - var(--sb) - 150px - 2 * var(--hs) - 46px); max-height: calc(100dvh - var(--st) - var(--sb) - 150px - 2 * var(--hs) - 46px); }
html.touch #tracker .q { margin-bottom: 4px; }
html.touch #tracker .q b { font-size: 12px; }
html.touch #tracker .q.next .where { font-size: 10.5px; }

/* ── Кнопки вгорі праворуч і меню під ними ── */
#tquick { position: fixed; top: var(--st); right: calc(var(--sr) + var(--mini) + 10px); display: flex; gap: 5px; }
#tquick .slot, html.touch #menu .slot { --p: #2b3044; --g: #6f6238; }
#tquick .slot { width: 40px; height: 40px; border-radius: 50%; }
#tquick .slot > .ic { width: 56%; height: 56%; fill: url(#gGold); }
html.touch #menu { display: none; right: calc(var(--sr) + var(--mini) + 10px); top: calc(var(--st) + 46px); bottom: auto; z-index: 40; grid-template-columns: 1fr 1fr; gap: 4px; padding: 6px; width: min(330px, calc(100vw - var(--sl) - var(--sr) - var(--mini) - 20px));
  max-height: calc(100vh - var(--st) - var(--sb) - 52px); max-height: calc(100dvh - var(--st) - var(--sb) - 52px); overflow-y: auto; }
html.touch.tmenu #menu { display: grid; }
html.touch #menu .slot { width: auto; height: auto; min-height: 40px; border-radius: 6px; justify-content: flex-start; gap: 9px; padding: 0 10px 0 9px; color: var(--gold-hi); font-weight: 600; }
html.touch #menu .slot::before { content: attr(data-name); order: 2; position: static; background: none; border-radius: 0; height: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.touch #menu .slot::after { border-radius: 6px; }
html.touch #menu .slot > .ic, html.touch #menu .sndIco .ic { width: 22px; height: 22px; flex: none; }
html.touch #menu .sndIco { width: auto; height: auto; }
/* Звук і графіка: плашка розкривається просто в меню, під своїм рядком. */
html.touch #menu .snd { order: 9; grid-column: 1 / -1; flex-wrap: wrap; }
html.touch #menu .snd .sndIco, html.touch #menu .snd::before { height: 40px; line-height: 40px; display: flex; align-items: center; }
html.touch .sndBox { position: static; width: 100%; padding: 0 0 8px; background: none; border: 0; box-shadow: none; order: 3; grid-template-columns: auto 1fr; align-items: center; gap: 4px 10px; text-align: left; }
html.touch #menu .snd.open .sndBox { display: grid; }
html.touch .sndBox small, html.touch .sndBox input + small { margin: 0; }
html.touch .sndBox input { width: 100%; height: 34px; margin: 0; }
html.touch .gfxPick { gap: 5px; }
html.touch .gfxPick b { min-height: 40px; display: flex; align-items: center; justify-content: center; font-size: .95rem; }

/* ── Джойстик ── */
#joy { position: fixed; left: calc(var(--sl) + 12px); bottom: calc(var(--sb) + 12px); width: var(--joy); height: var(--joy); border-radius: 50%; touch-action: none;
  background: radial-gradient(circle, rgba(13, 15, 24, .18) 0, rgba(13, 15, 24, .5) 72%); box-shadow: inset 0 0 0 2px rgba(230, 200, 119, .5), inset 0 0 0 3px rgba(0, 0, 0, .55), 0 4px 14px rgba(0, 0, 0, .4); }
#joy i { position: absolute; left: 29%; top: 29%; width: 42%; height: 42%; border-radius: 50%; pointer-events: none; background: var(--metal); box-shadow: 0 0 0 1px #000, inset 0 0 0 3px rgba(18, 20, 29, .85), 0 3px 8px rgba(0, 0, 0, .6); }
#joy.on { box-shadow: inset 0 0 0 2px var(--cyan), inset 0 0 0 3px rgba(0, 0, 0, .55), 0 0 14px rgba(114, 228, 255, .35); }

/* ── Панель дій 2×6 і кнопки дій праворуч унизу ── */
html.touch #bottom { left: auto; right: calc(var(--sr) + 2 * var(--hs) + 14px); bottom: var(--sb); transform: none; gap: 4px; }
html.touch #barRow::before, html.touch #barRow::after { display: none; }
html.touch #hotbar { display: grid; grid-template-columns: repeat(6, var(--hs)); gap: 4px; padding: 5px 6px; }
html.touch #hotbar .slot { width: var(--hs); height: var(--hs); }
html.touch #hotbar .slot:nth-child(4n + 1):not(:first-child) { margin-left: 0; }
html.touch #xpBar { height: .55rem; }
#tbtns { position: fixed; right: var(--sr); bottom: calc(var(--sb) + .55rem + 9px); display: grid; grid-template-columns: var(--hs) var(--hs); gap: 6px 4px; }
.tb { position: relative; width: var(--hs); height: var(--hs); border-radius: 50%; overflow: hidden; display: flex; align-items: center; justify-content: center; border: 1px solid #000;
  background: radial-gradient(circle at 50% 35%, #3a3320, #15120a); box-shadow: inset 0 0 0 2px rgba(230, 200, 119, .6), 0 3px 10px rgba(0, 0, 0, .6); transition: transform .06s, filter .1s; }
.tb:active { transform: scale(.92); filter: brightness(1.35); }
.tb .ic { width: 58%; height: 58%; fill: url(#gIvory); pointer-events: none; }
.tb .ic.art { width: 100%; height: 100%; border-radius: 50%; }
.tb::after { content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none; box-shadow: inset 0 0 0 2px rgba(230, 200, 119, .75), inset 0 0 0 3px rgba(0, 0, 0, .6); }
.tb.tb-attack::after { box-shadow: inset 0 0 0 2px #ffb08a, inset 0 0 0 3px rgba(0, 0, 0, .6), inset 0 0 12px rgba(255, 110, 70, .5); }
.tb.tb-cancel { background: radial-gradient(circle at 50% 35%, #4a2420, #1e0d0b); } .tb.tb-cancel .ic { fill: url(#gRed); }
html.touch #castbar { position: fixed; left: 50%; bottom: 36%; transform: translateX(-50%); margin: 0; width: calc(300px * var(--k)); }
html.touch #hint { bottom: calc(var(--sb) + 3px); max-width: 70vw; background: rgba(6, 8, 14, .93); }   /* підказка про вибір речі для файн-тюну: тоді відкриті рюкзак і персонаж */
html.touch #banner { top: 26%; font-size: 2.2rem; }

/* ── Чат: згорнутий — три останні рядки між джойстиком і панеллю; розгорнутий — угорі, поле над журналом ── */
html.touch #chat { left: calc(var(--sl) + var(--joy) + 26px); right: calc(var(--sr) + 8 * var(--hs) + 58px); width: auto; bottom: var(--sb); height: 4.3em; background: none; border: 0; box-shadow: none; pointer-events: none; }
html.touch #chatLog { overflow: hidden; padding: 0 4px; font-size: .95rem; line-height: 1.32; -webkit-mask-image: linear-gradient(transparent, #000 45%); mask-image: linear-gradient(transparent, #000 45%); }
html.touch #chatIn, #chatSend, #chatClose { display: none; }
html.touch.tchat #chat { left: var(--sl); top: var(--st); right: auto; bottom: auto; width: min(500px, 64vw); height: min(260px, calc(100vh - var(--st) - var(--sb))); z-index: 45; pointer-events: auto;
  display: grid; grid-template-columns: 1fr auto auto; grid-template-rows: auto 1fr; background: rgba(9, 10, 17, .93); border: 1px solid #000; box-shadow: inset 0 0 0 1px rgba(230, 200, 119, .4), 0 8px 24px rgba(0, 0, 0, .6); }
html.touch.tchat #chatIn { display: block; grid-area: 1 / 1; min-width: 0; min-height: 42px; border-top: 0; border-bottom: 1px solid rgba(230, 200, 119, .25); }
html.touch.tchat #chatSend { display: inline-flex; grid-area: 1 / 2; margin: 3px 4px; align-self: center; }
html.touch.tchat #chatClose { display: block; grid-area: 1 / 3; position: relative; width: 40px; height: 36px; margin: 3px 4px 3px 0; align-self: center; border-radius: 4px; background: linear-gradient(#3b2420, #1f100e); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px rgba(255, 141, 122, .4); }
#chatClose::before, #chatClose::after { content: ''; position: absolute; left: 50%; top: 50%; width: 46%; height: 2px; background: #ffc9bd; border-radius: 1px; transform: translate(-50%, -50%) rotate(45deg); }
#chatClose::after { transform: translate(-50%, -50%) rotate(-45deg); }
html.touch.tchat #chatLog { grid-area: 2 / 1 / 3 / 4; overflow-y: auto; padding: 6px 9px; -webkit-mask-image: none; mask-image: none; }

/* ── Вікна: на своїх місцях, у висоту екрана, з прокруткою всередині ── */
html.touch .win { top: var(--st) !important; max-width: calc(100vw - var(--sl) - var(--sr)); }
html.touch .win .head { height: 40px; cursor: default; padding-right: 4px; }
html.touch .win .x { width: 42px; height: 34px; }
html.touch .win .x::before, html.touch .win .x::after { width: 36%; }
html.touch .win .body, html.touch .win.w-char .body { padding: 9px 8px 8px; max-height: calc(100vh - var(--st) - var(--sb) - 46px); max-height: calc(100dvh - var(--st) - var(--sb) - 46px); }
/* Рюкзак — праворуч; персонаж, розмова й трейд — ліворуч і не ширші за місце, що лишає рюкзак: пари вікон не перекриваються. */
html.touch .win.w-inv { left: auto !important; right: var(--sr); width: var(--invw) !important; }
html.touch .win.w-char, html.touch .win.w-npc, html.touch .win.w-trade { left: var(--sl) !important; max-width: calc(100vw - var(--sl) - var(--sr) - var(--invw) - 6px); }
html.touch .win.w-skills, html.touch .win.w-quests, html.touch .win.w-map { left: 50% !important; transform: translateX(-50%); }
html.touch .grid { gap: 3px; padding: 5px; }
html.touch .charwin { grid-template-columns: calc(262px * var(--k)) 1fr; gap: 8px; }
html.touch .pd-stage { height: calc(230px * var(--k)); }
html.touch canvas.doll { touch-action: pan-y; }
html.touch .stats { grid-template-columns: 1fr; }
html.touch .sgroup { padding: 4px 7px 5px; }
html.touch .acthead { flex-wrap: wrap; gap: 6px; }
html.touch .sk { min-height: 46px; }
html.touch .line { min-height: 46px; }
html.touch .rcp .qty, html.touch .credrow input, html.touch #popup .cntrow input { min-height: 38px; }
html.touch .craftbar .find { min-height: 38px; min-width: 120px; }
html.touch .win.w-map .body { padding: 6px; }
html.touch .wmap { gap: 8px; align-items: stretch; }
html.touch .wleg { overflow-y: auto; max-height: calc(100vh - var(--st) - var(--sb) - 60px); max-height: calc(100dvh - var(--st) - var(--sb) - 60px); padding-right: 4px; }
html.touch .tcols { gap: 6px; } html.touch .tcol { padding: 6px; }
html.touch .tcol .grid.g4 { grid-template-columns: repeat(4, minmax(0, var(--slot))); }
html.touch .tcol .grid.g4 .slot { width: 100%; height: auto; aspect-ratio: 1; }

/* ── Підказка, яку відкрив довгий дотик: по ній можна тапати, під нею — дії ── */
html.touch #tooltip { max-width: min(calc(318px * var(--k) + 40px), calc(100vw - 16px)); }
#tooltip.touch { pointer-events: auto; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; }
.tt-acts { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 9px 9px; border-top: 1px solid #000; box-shadow: inset 0 1px 0 0 rgba(230, 200, 119, .25); background: rgba(0, 0, 0, .25); }
.tt-acts .btn { flex: 1 1 auto; min-height: 40px; }

/* ── Плашки й оверлеї ── */
html.touch #popup { top: 50%; transform: translate(-50%, -50%); padding: 14px 18px 12px; max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); overflow-y: auto; }
html.touch .overlay { overflow-y: auto; padding: var(--st) var(--sr) var(--sb) var(--sl); }
html.touch .card { padding: 16px 20px 14px; margin: auto; }
html.touch .card h2 { font-size: 1.6rem; margin-bottom: 6px; }
html.touch .lead { margin-bottom: 10px; }
html.touch .crest { width: 44px; height: 44px; margin-bottom: 4px; }

/* ── Вхід: дві колонки — назва ліворуч, форма праворуч, щоб усе вмістилося у висоту телефона ── */
html.touch .card.logo { width: min(700px, calc(100vw - var(--sl) - var(--sr) - 8px)); display: grid; grid-template-columns: 1fr 1.05fr; grid-template-rows: auto auto auto 1fr auto; column-gap: 24px; align-items: center; padding: 14px 22px 12px; }
html.touch .card.logo .sigil { grid-area: 1 / 1; width: 40px; height: 40px; margin-bottom: 0; }
html.touch .card.logo h1 { grid-area: 2 / 1; font-size: 3.4rem; }
html.touch .tagline { grid-area: 3 / 1; margin: 4px 0 8px; font-size: .8rem; letter-spacing: .22em; }
html.touch .card.logo .lead { grid-area: 4 / 1; align-self: start; margin: 0; font-size: .95rem; }
html.touch #loginHint { grid-area: 5 / 1; margin: 0; }
html.touch .authTabs { grid-area: 1 / 2; margin-bottom: 8px; }
html.touch .card.logo form { grid-area: 2 / 2 / 5 / 3; align-self: start; gap: 7px; }
html.touch #loginMsg { grid-area: 5 / 2; margin: 4px 0 0; }
html.touch .card input, html.touch .authBox input, html.touch #createName { padding: .5em .8em; min-height: 42px; }
html.touch .card form .btn { margin-top: 2px; }

/* ── Вибір і створення персонажа: колонки вужчі й нижчі, головна кнопка завжди на видноті ── */
html.touch .overlay.clear { padding: var(--st) var(--sr) var(--sb) var(--sl); overflow: hidden; }
html.touch .side { width: calc(300px * var(--k)); max-width: 36vw; padding: 11px 12px 10px; gap: 5px; margin: 0; }
html.touch .side.right { width: calc(330px * var(--k)); }
html.touch .side h2 { font-size: 1.3rem; }
html.touch .side h3 { margin: 4px 0 2px; }
html.touch .choice { padding: 5px 8px 5px 5px; gap: 8px; min-height: 44px; }
html.touch .choice .ico, html.touch #charList .choice .ico, html.touch #charList .free i { width: 34px; height: 34px; }
html.touch #charInfo .crestBig { display: none; }
html.touch #charInfo h3 { font-size: 1.5rem; }
html.touch #charInfo .lvl { margin: 3px 0 2px; } html.touch #charInfo .lvl span { font-size: 1.4rem; }
html.touch #charPlay, html.touch #createBtn { position: sticky; bottom: 0; z-index: 2; flex: none; outline: 6px solid #10121b; }
html.touch #createInfo { margin: 4px 0 2px; }
html.touch #createInfo h3 { font-size: 1.15rem; margin-bottom: 3px; }
html.touch .sigbox { margin: 6px 0; padding: 6px 8px; }

/* ── Телефон тримають вертикально ── */
#rotate { display: none; z-index: 200; background: radial-gradient(ellipse at center, #141826, #05060a); }
#rotate .card { width: min(340px, 92vw); }
#rotate .phone { width: 46px; height: 80px; margin: 2px auto 16px; border-radius: 9px; border: 3px solid var(--gold); box-shadow: 0 0 16px rgba(230, 200, 119, .35); animation: rotatePhone 2.6s ease-in-out infinite; }
#rotate .phone i { display: block; width: 14px; height: 3px; margin: 6px auto 0; border-radius: 2px; background: var(--gold); }
#rotate .btn { margin-bottom: 10px; }
@keyframes rotatePhone { 0%, 18% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) { html.touch #rotate { display: flex; } }
