/* The page around Dawn: the desktop fills the tab, and the tools that are
   HTML (notes, apps, the Linux terminal) are drawn as Dawn's own windows —
   its ground, its hairlines, its small radii and its dots. */
:root {
  color-scheme: dark;
  --ground: #0d0e12;
  --sheet: #16171d;
  --sheet-raised: #1c1e25;
  --well: #0f1014;
  --line: #ffffff17;
  --line-strong: #ffffff2b;
  --ink: #e7e9f0;
  --ink-soft: #b3b7c6;
  --ink-faint: #7f8496;
  --warm: #e9b35a;
  --warm-ink: #1c1405;
  --cool: #7aa7ff;
  --ok: #58c99a;
  --radius: 8px;
  --radius-small: 6px;
  --tint: #ffffff0d;
  --tint-strong: #ffffff17;
  --shade: #000b;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font: 13px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}
/* Dawn in a light look: the same windows on paper. */
:root[data-look="light"] {
  color-scheme: light;
  --sheet: #f7f6f2;
  --sheet-raised: #ffffff;
  --well: #edece7;
  --line: #0000001c;
  --line-strong: #00000036;
  --ink: #1b1c22;
  --ink-soft: #474a57;
  --ink-faint: #787c8a;
  --warm: #b37312;
  --warm-ink: #ffffff;
  --cool: #2f63c9;
  --ok: #1f9a68;
  --tint: #0000000a;
  --tint-strong: #00000014;
  --shade: #0004;
}
* { box-sizing: border-box }
[hidden] { display: none !important }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--ground) }
main { position: relative; height: 100%; height: 100dvh }
/* A phone's home indicator and rounded corners lie over the foot of the
   page, and a notch over its sides when it is held sideways: the desktop
   ends before them. Zero wherever the browser reports no such inset. Only
   in a page of its own (app.mjs): framed by another page, the insets are
   that page's to keep clear of, and the frame already ends before them. */
@supports (height: env(safe-area-inset-bottom)) {
  .own-window main {
    height: calc(100dvh - env(safe-area-inset-bottom, 0px));
    margin-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
  }
  .own-window header { margin-bottom: env(safe-area-inset-bottom, 0px) }
  .own-window header[data-place="end"] { margin-right: env(safe-area-inset-right, 0px) }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap }
:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px }

/* The desktop */
#desktop-controls, #desktop-viewport { position: absolute; inset: 0 }
#dawn-desktop { display: block; width: 100%; height: 100%; background: var(--ground); touch-action: none }
#dawn-desktop.interactive { cursor: none }
#desktop-command.sr-only { margin: 0; inset: auto auto 0 0 }

/* Before the first frame, and when something stops: one quiet line with
   Dawn's dots. Empty, it is not there. */
#desktop-status, #boot-choice {
  position: absolute; z-index: 3; left: 50%; bottom: 3.25rem; translate: -50% 0;
  display: flex; align-items: center; gap: .6rem; max-width: min(92vw, 34rem); margin: 0;
  padding: .5rem .85rem; border: 1px solid var(--line); border-radius: 999px;
  background: color-mix(in srgb, var(--sheet) 92%, transparent); color: var(--ink-soft);
  box-shadow: 0 .6rem 2rem var(--shade); backdrop-filter: blur(14px);
}
#desktop-status:empty { display: none }
#desktop-status::before {
  content: ""; flex: none; width: 22px; height: 6px;
  background: radial-gradient(circle 2px, var(--warm) 98%, #0000) 0 0 / 8px 6px repeat-x;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots { from { clip-path: inset(0 100% 0 0) } to { clip-path: inset(0 -34% 0 0) } }
#boot-choice { bottom: .75rem; color: var(--warm); text-decoration: none }
#boot-choice:hover { border-color: var(--line-strong) }

/* Tools: a small launcher in the middle of the status bar, where the bar
   is empty. It is there once the desktop is. */
header { position: fixed; z-index: 5; left: 50%; bottom: 3px; translate: -50% 0; max-width: 100%; visibility: hidden }
body:has(#desktop-viewport[data-phase="desktop"]) header { visibility: visible }
/* On a narrow display the bar's middle belongs to its own words and
   notices. DisplayOS keeps the right end free there (96 px), and the
   launcher and its menu stand at that end. */
header[data-place="end"] { left: auto; right: 8px; translate: none }
header[data-place="end"] #tools summary kbd { display: none }
header[data-place="end"] #tools nav { left: auto; right: 0; translate: none; transform-origin: 100% 100% }
#tools { position: relative }
#tools summary {
  list-style: none; cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: .45rem;
  height: 20px; padding: 0 .6rem; border: 1px solid #0000; border-radius: 999px;
  color: var(--ink-faint); font-size: 11px; letter-spacing: .02em;
  transition: color .16s, border-color .16s, background .16s;
}
#tools summary::-webkit-details-marker { display: none }
#tools summary::before {
  content: ""; width: 8px; height: 8px;
  background: radial-gradient(circle 1.25px, currentColor 98%, #0000) 0 0 / 4px 4px;
}
#tools summary kbd { font: 10px var(--mono); opacity: .7 }
#tools summary:hover, #tools summary:focus-visible, #tools[open] summary {
  color: var(--ink); border-color: var(--line-strong); background: color-mix(in srgb, var(--sheet-raised) 92%, transparent);
}
#tools nav {
  position: absolute; left: 50%; bottom: calc(100% + .5rem); translate: -50% 0; width: max-content; max-width: 94vw;
  display: grid; gap: 2px; padding: .35rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--sheet) 94%, transparent); backdrop-filter: blur(18px);
  box-shadow: 0 1rem 3rem var(--shade), 0 0 0 1px #0000001f;
  transform-origin: 50% 100%; animation: rise .18s var(--ease);
}
#tools nav :is(a, button) {
  all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: .6rem;
  min-height: 2.1rem; padding: 0 .65rem; border-radius: var(--radius-small); color: var(--ink-soft); white-space: nowrap;
}
#tools nav :is(a, button)::before {
  content: ""; flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-faint);
}
#tools nav :is(a, button):is(:hover, :focus-visible) { background: var(--tint-strong); color: var(--ink) }
#tools nav :is(a, button):focus-visible { outline: 2px solid var(--warm); outline-offset: -2px }
#tools nav a[aria-current] { color: var(--ink) }
#tools nav a[aria-current]::before { background: var(--warm); box-shadow: 0 0 0 3px #e9b35a26 }
#tools nav small { margin-left: auto; padding-left: 1.2rem; font-size: 11px; color: var(--ink-faint) }
#tools nav button { position: relative; margin-top: 5px }
#tools nav button::after { content: ""; position: absolute; inset: -3px 0 auto; height: 1px; background: var(--line) }
@keyframes rise { from { opacity: 0; transform: translateY(6px) scale(.98) } }

/* A tool is a window of the desktop: title band, hairline, small radius. */
#tool-window, #last-window {
  position: absolute; border: 1px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--sheet) 96%, transparent); backdrop-filter: blur(20px);
  box-shadow: 0 1.2rem 4rem var(--shade), 0 0 0 1px #0000001f;
  transition: opacity .12s;
}
/* While DisplayOS gathers the window from grains on the desktop under it,
   the window itself is not shown yet. */
:is(#tool-window, #last-window).arriving { opacity: 0; transition: none }
#tool-window {
  z-index: 2; inset: 3.4rem 1rem auto auto; width: min(58%, 40rem); max-height: calc(100% - 5.4rem);
  overflow: auto; overscroll-behavior: contain; padding: 0 .9rem .9rem;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) #0000;
}
.window-title {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: .6rem;
  height: 2.5rem; margin: 0 -.9rem .75rem; padding: 0 .5rem 0 .9rem;
  background: var(--sheet); border-bottom: 1px solid var(--line);
}
.window-title::before {
  content: ""; flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--warm);
}
.window-title h2 { flex: 1; margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: .01em }
/* The band's close button: the word stays for those who read it aloud. */
#close-tool {
  flex: none; width: 1.75rem; height: 1.75rem; border-radius: var(--radius-small); overflow: hidden;
  display: grid; place-items: center; color: #0000; font-size: 0; text-decoration: none;
}
#close-tool::before { content: "×"; font: 300 18px/1 system-ui, sans-serif; color: var(--ink-faint) }
#close-tool:hover { background: var(--tint-strong) }
#close-tool:hover::before { color: var(--ink) }

/* What a tool shows: Dawn's work surface, or a program's output. */
.surface {
  position: relative; overflow: hidden; aspect-ratio: 16 / 9;
  border: 1px solid var(--line); border-radius: var(--radius-small); background: var(--well);
}
.surface canvas { display: block; width: 100%; height: 100% }
/* The note lies on the work surface DisplayOS painted, which keeps its own
   dark ground whatever look the desktop has. */
textarea {
  position: absolute; display: block; resize: none; border: 0; border-radius: 4px; padding: .65em;
  background: #15161b; color: #e7e9f0; color-scheme: dark; font: clamp(11px, 1.5vw, 15px)/1.55 var(--mono);
}
textarea:disabled { visibility: hidden }
#output, #native-output {
  position: absolute; margin: 0; padding: .7rem .8rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--well); color: var(--ink); font: 12px/1.6 var(--mono);
  scrollbar-width: thin; scrollbar-color: var(--line-strong) #0000;
}
.console-output { aspect-ratio: auto }
.console-output #surface { display: none }
.console-output pre:is(#output, #native-output) { position: static; width: 100% !important; height: clamp(6rem, 22vh, 15rem) !important }
.console-output pre:empty::before { content: "出力はここに表示されます"; color: var(--ink-faint) }

/* Controls */
form { margin: .9rem 0 0 }
form label, .toolbar label { display: block; margin-bottom: .4rem; color: var(--ink-faint); font-size: 11px; font-weight: 600; letter-spacing: .06em }
.row, .toolbar { display: flex; align-items: center; gap: .5rem }
.toolbar { flex-wrap: wrap; margin-top: .75rem }
.toolbar label { display: inline-flex; align-items: center; gap: .45rem; margin: 0 }
button, select, input:not([type=file]) {
  font: inherit; height: 2rem; padding: 0 .7rem; border: 1px solid var(--line); border-radius: var(--radius-small);
  background: var(--tint); color: var(--ink); transition: background .14s, border-color .14s, opacity .14s;
}
button { cursor: pointer; white-space: nowrap }
button:hover:not(:disabled), select:hover:not(:disabled) { background: var(--tint-strong); border-color: var(--line-strong) }
button:active:not(:disabled) { background: var(--tint) }
button:disabled, select:disabled, input:disabled { opacity: .42; cursor: default }
input:not([type=file]) { background: var(--well) }
input:not([type=file]):focus-visible, select:focus-visible, textarea:focus-visible { outline: 0; border-color: var(--warm); box-shadow: 0 0 0 3px #e9b35a2e }
.row input, .row select { flex: 1; min-width: 0 }
#command, #datagram-input { font-family: var(--mono); font-size: 12px }
/* The one thing a tool is for. */
:is(#generate, #save, #run, #open, #native-run, #datagram-send):not(:disabled) {
  background: var(--warm); border-color: var(--warm); color: var(--warm-ink); font-weight: 600;
}
:is(#generate, #save, #run, #open, #native-run, #datagram-send):hover:not(:disabled) { filter: brightness(1.08) }

/* A status is a lamp and a line. */
#status, #linux-status, #native-status, #panel-placement, #resident-name:not(:empty) {
  display: flex; align-items: center; gap: .5rem; min-height: 1.5rem; margin: .8rem 0 0; color: var(--ink-soft); font-size: 12px;
}
:is(#status, #linux-status, #native-status)::before {
  content: ""; flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--ok);
}
#panel-placement { color: var(--warm) }
#datagram-response { display: block; margin-top: .6rem; overflow-wrap: anywhere; white-space: pre-wrap; font: 12px/1.6 var(--mono); color: var(--ink-soft) }
details:not(#tools) { margin-top: .9rem; color: var(--ink-faint); font-size: 12px }
details:not(#tools) summary { cursor: pointer; width: fit-content }
details:not(#tools) summary:hover { color: var(--ink-soft) }
details pre, dd { margin: .4rem 0 .8rem; font: 11.5px/1.6 var(--mono); color: var(--ink-soft); overflow-wrap: anywhere; white-space: pre-wrap }
dt { margin-top: .5rem }

/* A window a program drew: its pixels under a title band. */
#last-window {
  z-index: 1; inset: 3.4rem auto auto 4.25rem; max-width: 42%; margin: 0; overflow: hidden;
  display: flex; flex-direction: column-reverse; align-items: start;
}
#last-window figcaption {
  align-self: stretch; display: flex; align-items: center; gap: .55rem; height: 1.9rem; padding: 0 .7rem;
  border-bottom: 1px solid var(--line); background: var(--sheet); color: var(--ink-soft); font-size: 12px;
}
#last-window figcaption::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--cool) }
#wayland-surface { max-width: 100%; touch-action: none }
#wayland-frame { display: block; max-width: 100%; max-height: 50vh; width: auto; height: auto; object-fit: fill; touch-action: none }

@media (max-width: 700px) {
  #tool-window { inset: auto .5rem 2.1rem; width: auto; max-height: 58%; transform-origin: 50% 100% }
  #last-window { inset: 3.2rem auto auto .5rem; max-width: 92%; max-height: 40% }
  #wayland-frame { max-height: 32vh }
  textarea, .row input, #command { font-size: 16px }
  #metrics:not(:empty) {
    position: static; display: block; width: auto; height: auto; margin-top: .65rem;
    clip-path: none; overflow: visible; white-space: normal; color: var(--warm); font-size: 13px;
  }
}
/* Nothing to hover with: the launcher is easier to hit. */
@media (hover: none) {
  header { bottom: 1px }
  #tools summary { height: 24px; color: var(--ink-soft) }
  #tools summary kbd { display: none }
}
@media (prefers-reduced-motion: reduce) {
  #tools nav { animation: none }
  #desktop-status::before { animation: none }
  * { transition: none !important }
}
