/* Kiri desktop chrome and theme tokens (dark default, light under [data-theme="light"]). */
:root {
  --bg: #0F1419;
  --panel: #171D24;
  --raised: #1E252D;
  --side: #121920;
  --line: #2A313A;
  --text: #F2F0EB;
  --muted: #98A1AC;
  --faint: #66707C;
  --term-bg: #0B0F13;
  --term-fg: #F2F0EB;
  --row-hover: rgba(255, 255, 255, 0.04);

  --blue: #0D6EFD;
  --blue-hover: #0B5ED7;
  --blue-active: #0A58CA;
  --blue-light: #6EA8FE;
  --moss: #3FB68B;
  --sun: #FFC23D;
  --red: #DC3545;
  --ext: #A78BFA;

  --sun-text: #FFC23D;
  --red-text: #F87171;
  --ext-text: #C4B5FD;

  --ui-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Noto Sans", sans-serif;
  --mono-font: ui-monospace, "SF Mono", Menlo, monospace;

  /* Compatibility aliases mapped to Kiri tokens */
  --u-sans: var(--ui-font);
  --u-mono: var(--mono-font);
  --win: var(--panel);
  --win-ink: var(--text);
  --win-muted: var(--muted);
  --win-line: var(--line);
  --hb: var(--side);

  --chrome-bar: rgba(18, 25, 32, 0.92);
  --chrome-dock: rgba(23, 29, 36, 0.88);
  --chrome-ov: rgba(15, 20, 25, 0.84);
  --shadow-win: 0 2px 8px rgba(0, 0, 0, 0.36), 0 18px 48px rgba(0, 0, 0, 0.56);
  --shadow-win-focus: 0 4px 12px rgba(0, 0, 0, 0.44), 0 20px 56px rgba(0, 0, 0, 0.66);
  --shadow-menu: 0 8px 28px rgba(0, 0, 0, 0.45);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #F5F7FA;
  --panel: #FFFFFF;
  --raised: #F3F5F9;
  --side: #EDF0F5;
  --line: #DDE3EB;
  --text: #0F1419;
  --muted: #5E6773;
  --faint: #8A929C;
  --term-bg: #FFFFFF;
  --term-fg: #1F2328;
  --row-hover: rgba(15, 20, 25, 0.04);

  --sun-text: #8A6100;
  --red-text: #B42318;
  --ext-text: #6941C6;

  --chrome-bar: rgba(237, 240, 245, 0.94);
  --chrome-dock: rgba(255, 255, 255, 0.90);
  --chrome-ov: rgba(245, 247, 250, 0.88);
  --shadow-win: 0 2px 6px rgba(15, 20, 25, 0.10), 0 14px 36px rgba(15, 20, 25, 0.16);
  --shadow-win-focus: 0 4px 10px rgba(15, 20, 25, 0.14), 0 18px 46px rgba(15, 20, 25, 0.22);
  --shadow-menu: 0 8px 24px rgba(15, 20, 25, 0.16);

  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  font: calc(13px * var(--text-scale, 1))/1.4 var(--ui-font);
  color: var(--text);
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
}

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

[hidden] { display: none !important; }

/* Theme-switched Kiri brand marks */
.mark-light { display: none; }
.mark-dark { display: block; }
:root[data-theme="light"] .mark-dark { display: none; }
:root[data-theme="light"] .mark-light { display: block; }

/* Boot screen */
#boot {
  position: fixed;
  inset: 0;
  z-index: 99990;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--text);
  font-family: var(--ui-font);
  background: var(--bg);
}

.bt-center {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.bt-mark {
  width: 64px;
  height: 64px;
}

.bt-title {
  margin: 0;
  font-size: calc(22px * var(--text-scale, 1));
  font-weight: 600;
  letter-spacing: -0.01em;
}

.bt-bar {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.bt-fill {
  width: 8%;
  height: 100%;
  border-radius: 3px;
  background: var(--blue);
}

.bt-msg {
  margin: 0;
  min-height: 1.4em;
  color: var(--muted);
  font-size: calc(13px * var(--text-scale, 1));
  overflow-wrap: anywhere;
}

/* Desktop background */
#screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg) url("/assets/wallpapers/kiri-dusk.svg") center / cover no-repeat;
}

:root[data-theme="light"] #screen {
  background: var(--bg) url("/assets/wallpapers/kiri-day.svg") center / cover no-repeat;
}

/* Top bar */
.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  height: 30px;
  background: var(--chrome-bar);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  font-weight: 500;
  z-index: 1000;
}

.tb-btn {
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
}

.tb-btn:hover,
.tb-btn.on {
  background: var(--raised);
}

.tb-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.tb-launcher {
  padding: 0 6px;
}

.tb-mark {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

#clock {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-variant-numeric: tabular-nums;
}

.tray svg {
  width: 14px;
  height: 14px;
  display: block;
}

/* Dock */
.dock {
  position: absolute;
  left: 0;
  top: 30px;
  bottom: 0;
  width: 62px;
  background: var(--chrome-dock);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 6px;
  z-index: 900;
}

.dock .item {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  flex: none;
}

.dock .item:hover {
  background: var(--raised);
}

.dock .item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.dock .item .dots {
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  gap: 3px;
}

.dock .item .dots i {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--blue);
}

.dock .grow {
  flex: 1;
}

.dock .tip {
  display: none;
  position: absolute;
  left: 58px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-menu);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  font-size: calc(12px * var(--text-scale, 1));
  pointer-events: none;
  z-index: 920;
}

.dock .item:hover .tip,
.dock .item:focus-visible .tip {
  display: block;
}

.ico {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.ico img,
.ico svg {
  width: 40px;
  height: 40px;
  display: block;
}

.i-apps svg {
  width: 24px;
  height: 24px;
}

/* Dock edges: bottom (default, centred), left, or right */
html:not([data-dock]) .dock,
[data-dock="bottom"] .dock {
  top: auto;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  max-width: calc(100% - 16px);
  height: 58px;
  flex-direction: row;
  padding: 0 6px;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-menu);
}

html:not([data-dock]) .dock .grow,
[data-dock="bottom"] .dock .grow {
  flex: 0 0 1px;
  align-self: center;
  height: 32px;
  margin: 0 4px;
  background: var(--line);
}

html:not([data-dock]) .dock .item .dots,
[data-dock="bottom"] .dock .item .dots {
  left: 50%;
  top: auto;
  bottom: 1px;
  transform: translateX(-50%);
  display: flex;
}

html:not([data-dock]) .dock .tip,
[data-dock="bottom"] .dock .tip {
  left: 50%;
  top: auto;
  bottom: 60px;
  transform: translateX(-50%);
}

html:not([data-dock]) #ws,
[data-dock="bottom"] #ws {
  left: 0;
  bottom: 70px;
}

html:not([data-dock]) #ov,
[data-dock="bottom"] #ov {
  inset: 30px 0 70px 0;
}

[data-dock="right"] .dock {
  left: auto;
  right: 0;
  border-right: 0;
  border-left: 1px solid var(--line);
}

[data-dock="right"] .dock .item .dots {
  left: auto;
  right: 2px;
}

[data-dock="right"] .dock .tip {
  left: auto;
  right: 58px;
}

[data-dock="right"] #ws {
  left: 0;
  right: 62px;
}

[data-dock="right"] #ov {
  inset: 30px 62px 0 0;
}

/* Workspace and windows */
#ws {
  position: absolute;
  left: 62px;
  top: 30px;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

.win {
  position: absolute;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-win);
  display: flex;
  flex-direction: column;
  min-width: min(320px, calc(100vw - 16px));
  min-height: 200px;
  outline: none;
}

.win.focus {
  box-shadow: var(--shadow-win-focus);
  border-color: color-mix(in srgb, var(--blue) 45%, var(--line));
}

.win.max {
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0;
  border-width: 0;
}

.hb {
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--side);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  position: relative;
  cursor: default;
}

.hb .hb-icon {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  flex: none;
}

.hb .hb-icon img,
.hb .hb-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.hb .title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-weight: 600;
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.win:not(.focus) .hb .title {
  color: var(--muted);
}

.hb .sp {
  flex: 1;
}

.wbtns {
  display: flex;
  gap: 4px;
  margin-left: 6px;
}

.wbtns button {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.wbtns button:hover {
  background: var(--raised);
  color: var(--text);
}

.wbtns button[data-w="close"]:hover {
  background: var(--red);
  color: #FFFFFF;
}

.wbtns button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.wbtns svg {
  width: 10px;
  height: 10px;
  display: block;
}

.win-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  position: relative;
  user-select: text;
  -webkit-user-select: text;
}

/* Terminal windows use Kiri terminal surface tokens */
.w-terminal {
  background: var(--term-bg);
  color: var(--term-fg);
}

.w-terminal .hb {
  background: var(--side);
  color: var(--text);
  border-bottom-color: var(--line);
}

/* Shared window utility controls (6px radius, 32px controls, no pill buttons) */
.btn,
.hbtn,
.pill {
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.hbtn {
  min-width: 32px;
  padding: 0 9px;
  border-color: transparent;
  background: transparent;
}

.btn:hover,
.hbtn:hover,
.pill:hover {
  background: var(--raised);
  border-color: var(--line);
}

.hbtn.on {
  background: var(--raised);
  border-color: var(--line);
}

.btn:disabled,
.hbtn:disabled,
.pill:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn:focus-visible,
.hbtn:focus-visible,
.pill:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.btn.primary,
.pill.blue {
  background: var(--blue);
  border-color: var(--blue);
  color: #FFFFFF;
}

.btn.primary:hover,
.pill.blue:hover {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
}

.btn.primary:active,
.pill.blue:active {
  background: var(--blue-active);
  border-color: var(--blue-active);
}

.btn.danger,
.pill.red {
  background: var(--red);
  border-color: var(--red);
  color: #FFFFFF;
}

.btn.danger:hover,
.pill.red:hover {
  background: color-mix(in srgb, var(--red) 86%, #000000);
  border-color: color-mix(in srgb, var(--red) 86%, #000000);
}

/* Edge and corner resize handles (hidden while maximized) */
.grip {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 3;
}

.rz {
  position: absolute;
  z-index: 3;
}

.rz-n { top: 0; left: 12px; right: 12px; height: 5px; cursor: ns-resize; }
.rz-s { bottom: 0; left: 12px; right: 16px; height: 5px; cursor: ns-resize; }
.rz-e { right: 0; top: 12px; bottom: 16px; width: 5px; cursor: ew-resize; }
.rz-w { left: 0; top: 12px; bottom: 12px; width: 5px; cursor: ew-resize; }
.rz-ne, .rz-nw, .rz-sw { width: 12px; height: 12px; }
.rz-ne { top: 0; right: 0; cursor: nesw-resize; }
.rz-nw { top: 0; left: 0; cursor: nwse-resize; }
.rz-sw { bottom: 0; left: 0; cursor: nesw-resize; }
.win.max > .rz,
.win.max > .grip { display: none; }

/* Context and system menus */
.menu {
  position: fixed;
  z-index: 5000;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  min-width: 210px;
  max-width: calc(100vw - 12px);
  box-shadow: var(--shadow-menu);
}

.menu button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  width: 100%;
  min-height: 32px;
  text-align: left;
  padding: 5px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 6px;
  cursor: pointer;
}

.menu button:hover:not(:disabled) {
  background: var(--raised);
}

.menu button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.menu button:disabled {
  color: var(--muted);
  cursor: default;
}

.menu hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 2px;
}

.menu .ck {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--faint);
  display: grid;
  place-items: center;
  font-size: calc(11px * var(--text-scale, 1));
  flex: none;
}

.menu .ck.y {
  background: var(--blue);
  border-color: var(--blue);
  color: #FFFFFF;
}

/* Activities / app launcher overlay */
#ov {
  position: absolute;
  inset: 30px 0 0 62px;
  background: var(--chrome-ov);
  backdrop-filter: blur(10px);
  z-index: 950;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 16px 24px;
  overflow-y: auto;
}

.search {
  width: min(360px, 100%);
  height: 32px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  flex: none;
  cursor: text;
}

.search:focus-within {
  border-color: var(--blue);
  outline: 2px solid color-mix(in srgb, var(--blue) 35%, transparent);
  outline-offset: 0;
}

.search svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex: none;
  display: block;
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: calc(13px * var(--text-scale, 1));
}

.search input::placeholder {
  color: var(--faint);
}

.appgrid {
  margin-top: 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 116px));
  gap: 14px;
  width: min(840px, 100%);
  justify-content: center;
}

.app-t {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 6px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: center;
}

.app-t:hover,
.app-t.first {
  background: var(--panel);
  border-color: var(--line);
}

.app-t:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.app-t .ico {
  width: 60px;
  height: 60px;
  border-radius: 12px;
}

.app-t .ico img,
.app-t .ico svg {
  width: 60px;
  height: 60px;
}

.ov-empty {
  grid-column: 1 / -1;
  margin-top: 28px;
  color: var(--muted);
  text-align: center;
}

/* Toasts (top-right corner per contract) */
.toasts {
  position: fixed;
  top: 40px;
  right: 12px;
  z-index: 2500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  cursor: pointer;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  padding: 9px 14px;
  border-radius: 6px;
  font-size: calc(13px * var(--text-scale, 1));
  box-shadow: var(--shadow-menu);
  overflow-wrap: anywhere;
  max-width: 100%;
}

.toast.toast-error {
  border-left-color: var(--red);
  color: var(--red-text);
}

.toast:hover {
  background: var(--raised);
}

/* Power off / crash screen */
#off {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 99999;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--text);
  text-align: center;
}

.off-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#off h2 {
  margin: 0;
  color: var(--text);
  font-size: calc(20px * var(--text-scale, 1));
  font-weight: 600;
}

#off p {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.off-btn {
  margin-top: 8px;
  min-width: 140px;
  height: 32px;
  padding: 0 16px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #FFFFFF;
  font-weight: 600;
  font-size: calc(13px * var(--text-scale, 1));
  cursor: pointer;
}

.off-btn:hover {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
}

.off-btn:active {
  background: var(--blue-active);
  border-color: var(--blue-active);
}

.off-btn:focus-visible {
  outline: 2px solid var(--blue-light);
  outline-offset: 2px;
}

/* Narrow screens (390 px wide, no sideways scrolling) */
@media (max-width: 540px) {
  .tb-btn {
    padding: 0 6px;
    gap: 5px;
  }

  html:not([data-dock]) .dock,
  [data-dock="bottom"] .dock {
    height: 52px;
    padding: 0 4px;
    gap: 2px;
    max-width: calc(100% - 8px);
    overflow-x: auto;
    scrollbar-width: none;
  }

  html:not([data-dock]) .dock .item,
  [data-dock="bottom"] .dock .item {
    width: 40px;
    height: 40px;
  }

  html:not([data-dock]) .dock .ico,
  html:not([data-dock]) .dock .ico img,
  html:not([data-dock]) .dock .ico svg,
  [data-dock="bottom"] .dock .ico,
  [data-dock="bottom"] .dock .ico img,
  [data-dock="bottom"] .dock .ico svg {
    width: 32px;
    height: 32px;
  }

  html:not([data-dock]) .dock .i-apps svg,
  [data-dock="bottom"] .dock .i-apps svg {
    width: 22px;
    height: 22px;
  }

  html:not([data-dock]) #ws,
  [data-dock="bottom"] #ws {
    bottom: 64px;
  }

  html:not([data-dock]) #ov,
  [data-dock="bottom"] #ov {
    inset: 30px 0 64px 0;
  }

  .appgrid {
    margin-top: 20px;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 10px;
  }

  .app-t .ico,
  .app-t .ico img,
  .app-t .ico svg {
    width: 52px;
    height: 52px;
  }
}
