@font-face {
  font-family: "GNU Unifont";
  src: url("../fonts/unifont_jp-17.0.04.otf") format("opentype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --desktop-color: #547d78;
  --ui-face: #c6c6c6;
  --ui-light: #ffffff;
  --ui-mid: #858585;
  --ui-dark: #111111;
  --titlebar: #174f91;
  --titlebar-inactive: #707b88;
  --taskbar-height: 34px;
  --text: #111111;
}

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

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

html {
  background: var(--desktop-color);
  color: var(--text);
  font-family: "GNU Unifont", monospace;
  font-size: 15px;
}

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

button {
  color: inherit;
}

.desktop {
  position: fixed;
  inset: 0 0 var(--taskbar-height);
  overflow: hidden;
  background: var(--desktop-color);
}

.explorer,
.file-window {
  background: var(--ui-face);
  border: 1px solid var(--ui-dark);
  border-radius: 0;
  box-shadow:
    inset 1px 1px 0 var(--ui-light),
    inset -1px -1px 0 var(--ui-mid),
    1px 1px 0 rgba(0, 0, 0, 0.32);
}

.explorer {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: grid;
  width: min(322px, calc(100vw - 24px));
  height: min(500px, calc(100dvh - var(--taskbar-height) - 24px));
  min-height: 220px;
  grid-template-rows: 27px 27px minmax(0, 1fr) 24px;
  padding: 3px;
}

.panel-titlebar,
.file-titlebar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: var(--titlebar);
  font-weight: 700;
  letter-spacing: 0.01em;
  user-select: none;
}

.panel-titlebar {
  justify-content: flex-start;
  gap: 6px;
  padding: 2px 6px;
}

.panel-titlebar h1,
.file-titlebar h2 {
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.titlebar-app-icon {
  position: relative;
  width: 15px;
  height: 13px;
  flex: 0 0 auto;
  background: #f0d06a;
  border: 1px solid #10243a;
  box-shadow: inset 1px 1px #fff4a8;
}

.titlebar-app-icon::before {
  position: absolute;
  top: -3px;
  left: 1px;
  width: 7px;
  height: 3px;
  content: "";
  background: #f0d06a;
  border: 1px solid #10243a;
  border-bottom: 0;
}

.explorer-toolbar,
.explorer-status,
.file-statusbar {
  display: flex;
  align-items: center;
  min-width: 0;
  background: var(--ui-face);
  border: 1px solid;
  border-color: var(--ui-light) var(--ui-mid) var(--ui-mid) var(--ui-light);
}

.explorer-toolbar {
  margin-top: 3px;
  padding: 2px 6px;
  color: #333;
  font-size: 12px;
}

.explorer-content {
  position: relative;
  min-height: 0;
  margin-top: 3px;
  overflow: auto;
  color: #111;
  background: #fff;
  border: 2px solid;
  border-color: var(--ui-mid) var(--ui-light) var(--ui-light) var(--ui-mid);
  scrollbar-color: var(--ui-face) #eee;
}

.explorer-status,
.file-statusbar {
  margin-top: 3px;
  padding: 2px 5px;
  overflow: hidden;
  color: #333;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-tree {
  min-width: max-content;
  margin: 0;
  padding: 3px;
  list-style: none;
}

.tree-children {
  position: relative;
  padding: 0 0 0 18px;
}

.tree-children::before {
  position: absolute;
  top: 0;
  bottom: 7px;
  left: 10px;
  content: "";
  border-left: 1px dotted #8f8f8f;
}

.tree-row {
  display: flex;
  width: 100%;
  min-width: max-content;
  min-height: 29px;
  align-items: center;
  gap: 5px;
  padding: 2px 6px 2px 2px;
  text-align: left;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  cursor: default;
}

.tree-row:hover {
  background: #e8edf4;
  border-color: #b5c6dc;
}

.tree-row:focus-visible {
  color: #fff;
  background: #174f91;
  outline: 1px dotted #fff;
  outline-offset: -3px;
}

.tree-row:disabled {
  color: inherit;
}

.tree-arrow {
  width: 12px;
  flex: 0 0 12px;
  color: #222;
  font-size: 11px;
  text-align: center;
}

.tree-item-directory > .tree-row .tree-arrow::before {
  content: "▶";
}

.tree-item-directory[aria-expanded="true"] > .tree-row .tree-arrow::before {
  content: "▼";
}

.file-icon {
  position: relative;
  display: inline-block;
  width: 17px;
  height: 16px;
  flex: 0 0 17px;
}

.jstree-icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  background-color: transparent;
  background-image: url("../icons/jstree-32px.png");
  background-repeat: no-repeat;
}

.jstree-themeicon.jstree-folder {
  background-position: -263px -7px;
}

.jstree-themeicon.jstree-file {
  background-position: -103px -71px;
}

.file-icon {
  width: 14px;
  height: 17px;
  margin: 0 1px;
  background: #fff;
  border: 1px solid #4b4b4b;
  box-shadow: inset 1px 0 #d9e4ef;
}

.file-icon::before {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 5px;
  height: 5px;
  content: "";
  background: var(--ui-face);
  border-bottom: 1px solid #4b4b4b;
  border-left: 1px solid #4b4b4b;
}

.file-icon::after {
  position: absolute;
  right: 2px;
  bottom: 2px;
  left: 2px;
  height: 3px;
  content: "";
  background: #777;
}

.file-icon.kind-image::after { background: #28765b; }
.file-icon.kind-video::after { background: #674c91; }
.file-icon.kind-audio::after { background: #a36a19; }
.file-icon.kind-pdf::after { background: #a92e2e; }
.file-icon.kind-text::after { background: #4d6e95; }

.jstree-themeicon.is-loading {
  width: 17px;
  height: 17px;
  margin: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.jstree-themeicon.is-loading::before {
  position: absolute;
  inset: 0;
  display: grid;
  width: auto;
  height: auto;
  place-items: center;
  content: "⌛";
  color: #111;
  background: transparent;
  border: 0;
  font-size: 15px;
  line-height: 1;
  animation: loading-turn 0.75s steps(2, end) infinite;
}

.jstree-themeicon.is-loading::after {
  content: none;
}

@keyframes loading-turn {
  50% { transform: rotate(180deg); }
}

.tree-label {
  line-height: 1.35;
}

.tree-empty {
  padding: 8px 10px;
  color: #666;
  font-size: 13px;
}

.explorer-message {
  position: sticky;
  right: 4px;
  bottom: 4px;
  left: 4px;
  margin: 4px;
  padding: 4px 6px;
  color: #721c16;
  background: #fff1ef;
  border: 1px solid #b66158;
  font-size: 12px;
}

.explorer-message:empty {
  display: none;
}

.file-window {
  position: absolute;
  display: grid;
  min-width: 280px;
  min-height: 180px;
  max-width: calc(100vw - 8px);
  max-height: calc(100dvh - var(--taskbar-height) - 8px);
  grid-template-rows: 28px minmax(0, 1fr) 25px;
  padding: 3px;
  overflow: hidden;
  resize: none;
}

.file-titlebar {
  gap: 8px;
  padding: 2px 3px 2px 6px;
  background: var(--titlebar-inactive);
  touch-action: none;
}

.file-window.is-active .file-titlebar {
  background: var(--titlebar);
}

.file-window.is-dragging .file-titlebar {
  cursor: grabbing;
}

.file-title-group {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.file-title-group .file-icon {
  flex: 0 0 auto;
  transform: scale(0.86);
  transform-origin: center;
}

.file-title-group h2 {
  flex: 1 1 auto;
  min-width: 0;
}

.window-close {
  display: grid;
  width: 23px;
  height: 21px;
  flex: 0 0 23px;
  padding: 0 0 2px;
  place-items: center;
  color: #111;
  background: var(--ui-face);
  border: 1px solid;
  border-color: var(--ui-light) var(--ui-dark) var(--ui-dark) var(--ui-light);
  box-shadow: inset -1px -1px var(--ui-mid);
  font-family: "GNU Unifont", monospace;
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
}

.window-close:active {
  padding: 1px 0 1px 1px;
  border-color: var(--ui-dark) var(--ui-light) var(--ui-light) var(--ui-dark);
  box-shadow: inset 1px 1px var(--ui-mid);
}

.window-close:focus-visible {
  outline: 1px dotted #111;
  outline-offset: -4px;
}

.file-window-content {
  min-width: 0;
  min-height: 0;
  margin-top: 3px;
  overflow: auto;
  background: #fff;
  border: 2px solid;
  border-color: var(--ui-mid) var(--ui-light) var(--ui-light) var(--ui-mid);
}

.file-statusbar {
  margin-top: 3px;
  padding-right: 17px;
}

.window-resize-handle {
  position: absolute;
  right: 4px;
  bottom: 4px;
  z-index: 3;
  width: 13px;
  height: 13px;
  cursor: nwse-resize;
  touch-action: none;
}

.window-resize-handle::before,
.window-resize-handle::after {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 8px;
  height: 8px;
  content: "";
  border-right: 1px solid #555;
  border-bottom: 1px solid #555;
}

.window-resize-handle::after {
  right: 4px;
  bottom: 4px;
  width: 4px;
  height: 4px;
}

.text-viewer {
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 14px 16px;
  overflow-wrap: anywhere;
  color: #111;
  background: #fff;
  font-family: "GNU Unifont", monospace;
  font-size: 15px;
  line-height: 1.55;
  tab-size: 4;
  white-space: pre-wrap;
}

.text-viewer a,
.pdf-fallback a {
  color: #0000c8;
  text-decoration: underline;
}

.text-viewer a:visited,
.pdf-fallback a:visited {
  color: #6b237b;
}

.image-viewer,
.video-viewer,
.audio-viewer {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  background: #202225;
}

.image-viewer img,
.video-viewer video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.audio-viewer {
  padding: 18px;
  background: #ececec;
}

.audio-viewer audio {
  width: min(100%, 390px);
}

.pdf-viewer {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 260px;
  border: 0;
}

.pdf-fallback,
.viewer-error {
  margin: 0;
  padding: 18px;
  color: #222;
  background: #fff;
}

.taskbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10000;
  display: flex;
  height: var(--taskbar-height);
  align-items: center;
  gap: 6px;
  padding: 3px 5px;
  background: var(--ui-face);
  border-top: 1px solid var(--ui-light);
  box-shadow: inset 0 1px var(--ui-mid);
}

.taskbar-spacer {
  flex: 1;
  min-width: 0;
}

.taskbar-clock {
  display: grid;
  width: 76px;
  height: 25px;
  place-items: center;
  color: #111;
  border: 1px solid;
  border-color: var(--ui-mid) var(--ui-light) var(--ui-light) var(--ui-mid);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px), (pointer: coarse) and (max-width: 900px) {
  :root {
    --taskbar-height: calc(38px + env(safe-area-inset-bottom));
  }

  .explorer {
    inset: 8px 8px 8px;
    width: auto;
    height: auto;
    max-height: none;
  }

  .tree-row {
    min-height: 38px;
    padding-right: 10px;
    font-size: 15px;
  }

  .file-window {
    position: fixed;
    inset: 6px 6px calc(var(--taskbar-height) + 6px) !important;
    width: auto !important;
    height: auto !important;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    resize: none;
  }

  .window-resize-handle {
    display: none;
  }

  .file-titlebar {
    min-height: 34px;
    touch-action: auto;
  }

  .window-close {
    width: 30px;
    height: 28px;
    flex-basis: 30px;
  }

  body.mobile-window-open .explorer {
    visibility: hidden;
  }

  .text-viewer {
    padding: 13px;
    font-size: 15px;
  }

  .taskbar {
    align-items: flex-start;
    padding-top: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jstree-themeicon.is-loading::before {
    animation: none;
  }
}
