/* The desktop shell (docs/54 sections 2, 3, 6 and 12). Every rule hangs off html.wide (1280 px and up, wider than tall) or
   html.two (900 to 1279 px), which js/layout.js sets, so a phone sees none of it. The shell is one grid on #app:
     stage    the speaker (#talker) and the dock on the left, the picture or the exercise in the middle, #side on the right
     full     the screen spans the width
     column   the screen in the middle at phone width, the sides empty (a screen that has not opted in yet)
   app.layout(mode) sets #app[data-layout]; render() starts every screen as "column". */

/* nothing of the desktop is drawn on a phone */
#ambient, #talker, #side, #t-trail, #t-side { display: none; }

html:is(.wide, .two) {
  --bar-h: 58px; --pad-top: 22px; --pad-bottom: 22px; --gap: 28px;
  --gutter: max(28px, calc((100vw - 1760px) / 2));                                  /* three columns capped at about 1760 px, centred */
  --art-h: calc(var(--app-h, 100vh) - var(--bar-h) - var(--pad-top) - var(--pad-bottom));
  --art-w: calc(var(--art-h) * 841 / 1870);                                          /* the picture, whole, at its own shape */
  --mid: 560px;                                                                       /* the exercise, about a phone's width */
}
html.two { --mid: clamp(440px, 52vw, 560px); }

/* ------------------------------------------------------------------ the picture behind everything */
html:is(.wide, .two) #ambient {
  display: block; position: fixed; inset: -60px; z-index: 0; pointer-events: none; opacity: 0; transition: opacity .5s ease;
  background: #0d0f12 center / cover no-repeat; filter: blur(38px) saturate(1.1) brightness(.3); transform: scale(1.06);
}
html:is(.wide, .two) #ambient.on { opacity: 1; }
html:is(.wide, .two) #ambient::after { content: ""; position: absolute; inset: 0; background: radial-gradient(60% 80% at 50% 50%, transparent 0%, #0d0f12aa 70%, #0d0f12 100%); }
html:is(.wide, .two) body:has(#view.has-scene) #ambient { filter: blur(38px) saturate(1.1) brightness(.42); }

/* ------------------------------------------------------------------ the grid */
html:is(.wide, .two) #app {
  z-index: 1; max-width: none; margin: 0; display: grid; align-content: stretch; column-gap: var(--gap); row-gap: 0;
  padding: 0 var(--gutter) var(--pad-bottom); grid-template-rows: var(--bar-h) minmax(0, 1fr) auto;
}
html.wide #app[data-layout="stage"]  { grid-template-columns: minmax(0, 1fr) var(--mid) minmax(0, 1fr); grid-template-areas: "top top top" "talk view side" "dock view side"; }
html.wide #app[data-layout="column"] { grid-template-columns: minmax(0, 1fr) minmax(0, 720px) minmax(0, 1fr); grid-template-areas: "top top top" ". view ." ". dock ."; }
html.wide #app[data-layout="full"]   { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "view" "dock"; }
html.two #app[data-layout="stage"]   { grid-template-columns: minmax(0, 1fr) minmax(0, 480px) var(--mid) minmax(0, 1fr); grid-template-areas: "top top top top" ". talk view ." ". dock view ."; }
html.two #app[data-layout="column"]  { grid-template-columns: minmax(0, 1fr) minmax(0, 720px) minmax(0, 1fr); grid-template-areas: "top top top" ". view ." ". dock ."; }
html.two #app[data-layout="full"]    { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "view" "dock"; }
/* the picture takes the middle at its own shape (a story scene) */
html:is(.wide, .two) #app[data-layout="stage"]:has(> #view.has-scene) { --mid: var(--art-w); }

html:is(.wide, .two) .topbar { grid-area: top; margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter); height: var(--bar-h); gap: 14px;
  position: relative; z-index: 2; background: #0d0f12cc; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid #ffffff14; }
html:is(.wide, .two) body.app .topbar .iconbtn { width: 40px; height: 40px; background: #ffffff0a; border-color: #ffffff12; }
html:is(.wide, .two) body.app .topbar .topextra { width: 40px; font-size: 19px; }
html:is(.wide, .two) .topbar .title { flex: 1 1 auto; min-width: 210px; }
html:is(.wide, .two) #app.has-trail .topbar .title { flex: 0 0 210px; }
html:is(.wide, .two) .topbar .title b { font-size: 16px; }
html:is(.wide, .two) #t-side { display: inline-flex; }
html:is(.wide, .two) #t-side[hidden] { display: none; }
html:is(.wide, .two) #t-side svg { width: 22px; height: 22px; }
html:is(.wide, .two) #app:not([data-layout="stage"]) #t-side { display: none; }
/* Today with Akane and Talk have nothing for the help panel: no button for it there */
html:is(.wide, .two) #app:has(> #view.day) #t-side, html:is(.wide, .two) #app:has(> #view.talk) #t-side { display: none; }
/* the progress dots stay (a thin line on the bar's lower edge) until the outline takes their place */
html:is(.wide, .two) #pips { grid-area: top; align-self: end; z-index: 3; padding: 0; pointer-events: none; margin: 0 calc(var(--gutter) * -1); }
html:is(.wide, .two) #pips i { height: 2px; border-radius: 0; }
html:is(.wide, .two) #app.has-trail #pips { display: none; }

html:is(.wide, .two) #view { grid-area: view; min-width: 0; min-height: 0; margin-top: var(--pad-top); }
html:is(.wide, .two) #dock { grid-area: dock; margin-top: 14px; padding: 0; border-top: 0; background: none; width: 100%; justify-self: center; max-width: 720px; }
html.wide #app[data-layout="stage"] #dock { justify-self: end; max-width: 440px; }
html.two #app[data-layout="stage"] #dock { justify-self: stretch; max-width: none; }
html:is(.wide, .two) #app[data-layout="full"] #dock { max-width: 560px; }
html:is(.wide, .two) .dock-keys { margin-bottom: 8px; }

/* the speaker's column and the help column */
html:is(.wide, .two) #app[data-layout="stage"] #talker { display: flex; flex-direction: column; justify-content: flex-end; gap: 14px; grid-area: talk; min-width: 0; min-height: 0; margin-top: var(--pad-top); }
html.wide #app[data-layout="stage"] #talker { justify-self: end; width: 100%; max-width: 440px; }
html.two #app[data-layout="stage"] #talker { justify-self: stretch; }
html.wide #app[data-layout="stage"] #side { display: block; grid-area: side; min-width: 0; min-height: 0; margin-top: var(--pad-top); overflow-y: auto; justify-self: start; width: 100%; max-width: 440px; }
html.wide.side-hidden #app #side { display: none; }
/* two columns: the help panel is a drawer from the right, opened from the top bar */
html.two #app[data-layout="stage"] #side { display: block; position: fixed; top: var(--bar-h); right: 0; bottom: 0; width: min(400px, 92vw); z-index: 30; padding: 18px 18px 24px; overflow-y: auto;
  background: #12151af7; border-left: 1px solid var(--line); box-shadow: -20px 0 60px #000a; transform: translateX(105%); visibility: hidden; transition: transform .22s var(--ease), visibility 0s .22s; }
html.two #app.side-open[data-layout="stage"] #side { transform: none; visibility: visible; transition: transform .22s var(--ease); }

/* ------------------------------------------------------------------ the speaker */
html:is(.wide, .two) #talker.empty > * { display: none; }
#talker .tk-stage { position: relative; flex: 1 1 0; min-height: 120px; max-height: 600px; border-radius: 22px; overflow: hidden; border: 1px solid #ffffff14;
  background: radial-gradient(90% 70% at 50% 35%, #ffffff12, #ffffff03 70%); }
#talker .tk-stage.bare { flex: 0 0 auto; min-height: 0; border: 0; background: none; overflow: visible; }
#talker .tk-sprite { position: absolute; inset: 0; transition: opacity .25s; }
#talker .tk-stage.dim .tk-sprite { opacity: .45; }
#talker .tk-stage .tk-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; animation: fadeOnly .18s ease both;
  -webkit-mask-image: linear-gradient(180deg, #000 84%, transparent 100%); mask-image: linear-gradient(180deg, #000 84%, transparent 100%); }
#talker .tk-stage .tk-img.out { animation: none; }
#talker .tk-other { position: absolute; right: 12px; bottom: 12px; width: 88px; height: 88px; border-radius: 50%; }
#talker .tk-other .face { width: 88px; height: 88px; border-width: 2px; background: var(--bg); box-shadow: 0 6px 20px #000a; }
#talker .tk-plate { position: absolute; left: 14px; bottom: 12px; display: flex; align-items: baseline; gap: 8px; max-width: calc(100% - 120px); padding: 6px 12px; border-radius: 10px; background: #0d0f12d9; border: 1px solid #ffffff1f; font-size: 15px; }
#talker .tk-stage.bare .tk-plate { position: static; align-self: flex-start; }
#talker .tk-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#talker .tk-ja { color: var(--muted); font-weight: 500; font-family: var(--jp); }
#talker .tk-tag { font: 600 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; font-style: normal; color: var(--accent2); }

#talker .tk-card { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 14px 16px; border-radius: 16px; background: #171a20e6; border: 1px solid var(--line); }
#talker .tk-card.bare { padding: 0 4px; background: none; border: 0; overflow: visible; }
#talker .tk-card.bare > :not(.tk-keys) { display: none; }
#talker .tk-card.mute { display: none; }
#talker .tk-card.bare .tk-keys { margin-top: 0; }
#talker .tk-card[data-tone="good"] { border-color: #4ad17f77; }
#talker .tk-card[data-tone="bad"] { border-color: #e0a23c77; }
#talker .tk-text .gline { font-size: clamp(1.45rem, 3.3vh, 1.85rem); line-height: 2.3; letter-spacing: .02em; margin: 0; }
#talker .tk-text .gline rt { font-size: max(11px, .4em); }
#talker .tk-plain { margin: 0; font-size: 17.5px; line-height: 1.5; }
#talker .tk-plain b { color: var(--crema); font-weight: 700; }
#talker .tk-card[data-kind="narration"] .tk-plain, #talker .tk-card[data-kind="narration"] .tk-text { font-style: italic; color: #d9d4cc; }
#talker .tk-en { margin: 2px 0 0; color: #cfcac2; font-size: 16px; line-height: 1.45; }
#talker .tk-ja2 { margin: 8px 0 0; font: 400 15px/1.75 var(--jp); color: var(--muted); }
#talker .tk-extra { margin-top: 10px; }
#talker .tk-extra:empty { display: none; }
#talker .tk-extra .opts { margin-top: 0; }
#talker .tk-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
body.app #talker .tk-acts .btn { min-height: 38px; padding: 0 14px; font-size: 14px; }
body.app #talker .tk-acts .btn svg { width: 16px; height: 16px; }
#talker .tk-acts .tk-eng[aria-pressed="true"] { border-color: var(--crema); color: var(--crema); }
#talker .tk-keys { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font: 12px var(--mono); color: var(--dim); }
#talker .tk-hint { display: inline-flex; align-items: center; gap: 4px; }
#talker .tk-hint.off { opacity: .4; }
#talker .tk-keys kbd { font: 600 11px var(--mono); color: var(--muted); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; }

/* ------------------------------------------------------------------ the middle */
/* an exercise: a card the width of a phone, the speaker's bubble gone (it is in the left column) */
html:is(.wide, .two) #app[data-layout="stage"] .view:not(.has-scene) { padding: 24px 30px 28px; border-radius: 22px; border: 1px solid var(--line); background: #12151af2; box-shadow: 0 30px 80px #000a; }
html:is(.wide, .two) #app[data-layout="stage"] .view .say-slot { display: none; }
/* a story scene: the picture whole, at its own shape, with nothing over it but its label and Skip */
html:is(.wide, .two) #app[data-layout="stage"] .view.has-scene { border-radius: 18px; box-shadow: 0 30px 80px #000c, 0 0 0 1px #ffffff1a; }
html:is(.wide, .two) #app[data-layout="stage"] .scene-shade,
html:is(.wide, .two) #app[data-layout="stage"] .scene .sprite-slot,
html:is(.wide, .two) #app[data-layout="stage"] .scene .gs-slot,
html:is(.wide, .two) #app[data-layout="stage"] .scene .gs-phone,
html:is(.wide, .two) #app[data-layout="stage"] .scene .vnbox { display: none; }
html:is(.wide, .two) #app[data-layout="stage"] .scene-label { text-shadow: 0 1px 6px #000, 0 0 2px #000; }
html:is(.wide, .two) #app[data-layout="stage"] .gs-item { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 8px; border-radius: 14px; background: #0d0f12e6; border: 1px solid #ffffff22; }
html:is(.wide, .two) #app[data-layout="stage"] .gs-item img { width: 64px; height: 64px; object-fit: contain; border-radius: 10px; background: #ffffff10; }

/* ------------------------------------------------------------------ the outline in the top bar */
html:is(.wide, .two) #t-trail:not([hidden]) { display: flex; flex: 1 1 0; min-width: 0; justify-content: center; align-items: center; gap: 6px 16px; overflow: hidden; }
.trail .seg { flex: 0 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); white-space: nowrap; }
.trail .seg span { overflow: hidden; text-overflow: ellipsis; }
.trail .seg i { position: relative; flex: none; width: 30px; height: 4px; border-radius: 4px; background: #ffffff1c; overflow: hidden; }
.trail .seg i b { position: absolute; left: 0; top: 0; bottom: 0; width: var(--p, 0%); background: var(--ok); transition: width .25s; }
.trail .seg.done { color: #9fd8b4; }
.trail .seg.done i b { width: 100%; }
.trail .seg.part { color: var(--muted); }
.trail .seg.now { color: var(--text); }
html.wide .trail .seg i { width: clamp(14px, calc((100vw - 1060px) / 12), 30px); }
html.two .trail { gap: 6px 8px; }
html.two .trail .seg:not(.now) span { display: none; }
html.two .trail .seg i { width: 24px; }

/* ------------------------------------------------------------------ a sheet is a panel on the right */
html:is(.wide, .two) .sheet-back { background: #0008; }
html:is(.wide, .two) .sheet { left: auto; right: 0; top: 0; bottom: 0; width: min(420px, 100vw); max-width: none; max-height: none; height: 100%; margin: 0; display: flex; flex-direction: column;
  border: 0; border-left: 1px solid var(--line); border-radius: 0; padding: 22px 22px 22px; box-shadow: -20px 0 60px #000c; animation: panelIn .22s var(--ease); }
html:is(.wide, .two) .sheet-grab { display: none; }
html:is(.wide, .two) .sheet .sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
html:is(.wide, .two) .sheet .sheet-actions { margin-top: auto; padding-top: 16px; }
html:is(.wide, .two) .sheet .kicker { margin-top: 0; }
@keyframes panelIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
html:is(.wide, .two) .toast { bottom: 28px; }

/* ------------------------------------------------------------------ the mouse and the keyboard */
@media (hover: hover) {
  html:is(.wide, .two) body.app .opt:not(:disabled):hover { border-color: var(--crema); }
  html:is(.wide, .two) body.app .btn:not(.primary):not([disabled]):hover, html:is(.wide, .two) body.app .key:hover,
  html:is(.wide, .two) body.app .iconbtn:hover, html:is(.wide, .two) body.app .menu-item:hover, html:is(.wide, .two) body.app .askbtn:hover { border-color: var(--crema); }
  html:is(.wide, .two) body.app .btn.primary:not([disabled]):hover { background: #fff; }
}
html:is(.wide, .two) body.app :focus-visible { outline: 2px solid var(--crema); outline-offset: 2px; }
/* the number keys press the choices: show which number each one is */
html:is(.wide, .two) #app[data-layout="stage"] .opts { counter-reset: aw-opt; }
html:is(.wide, .two) #app[data-layout="stage"] .opts.grid > .opt { position: relative; }
html:is(.wide, .two) #app[data-layout="stage"] .opts.grid > .opt::before { counter-increment: aw-opt; content: counter(aw-opt); position: absolute; left: 8px; top: 6px; font: 600 11px var(--mono); color: var(--dim); }
html:is(.wide, .two) #app[data-layout="stage"] .opts:not(.grid) > .opt:not(.gs-opt):not(.vn-opt)::before { counter-increment: aw-opt; content: counter(aw-opt); flex: none; width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 7px; border: 1px solid var(--line); background: #ffffff08; font: 600 12px var(--mono); color: var(--muted); }

/* ------------------------------------------------------------------ a short window: a smaller speaker, the picture still full height */
@media (max-height: 699px) {
  html:is(.wide, .two) { --bar-h: 52px; --pad-top: 14px; --pad-bottom: 14px; }
  html:is(.wide, .two) #talker { gap: 10px; }
  #talker .tk-stage { min-height: 90px; }
  #talker .tk-card { padding: 10px 12px; }
  #talker .tk-text .gline { font-size: 1.5rem; line-height: 2.1; }
  #talker .tk-plain { font-size: 16px; }
  html:is(.wide, .two) #app[data-layout="stage"] .view:not(.has-scene) { padding: 18px 24px 20px; }
}
