@font-face {
  font-family: "NeoDunggeunmo";
  src:
    url("/font/neodgm.woff2") format("woff2"),
    url("/font/neodgm.woff") format("woff"),
    url("/font/neodgm.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "GalmuriMono9";
  src: url("/font/galmuri/GalmuriMono9.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "IyagiGGC";
  src: url("/font/iyagiggc/IyagiGGC.woff") format("woff");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #080c0a;
  --panel: #0d1714;
  --line: #2b6b61;
  --text: #dfffee;
  --muted: #7fb9aa;
  --accent: #ffbf4d;
  --accent-strong: #ffe08a;
  --button: #13251f;
  --xterm-font-size: 18px;
  --xterm-font-family: "NeoDunggeunmo";
  --ui-font-family: "NeoDunggeunmo";
  --emoji-font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Twemoji Mozilla";
  --xterm-scale: 1;
  --app-height: 100vh;
  --visual-offset-top: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.is-mud {
  --line: #246c7a;
  --text: #e3fff9;
  --muted: #7fb8c4;
  --accent: #7ed7ff;
  --accent-strong: #b8f0ff;
  --button: #11242a;
}

body.is-bbs {
  --line: #2b6b61;
  --text: #dfffee;
  --muted: #7fb9aa;
  --accent: #ffbf4d;
  --accent-strong: #ffe08a;
  --button: #13251f;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font-family), var(--emoji-font-family), ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 50%, rgba(0, 0, 0, 0.04) 50%),
    radial-gradient(circle at 50% 0%, #10261f 0, var(--bg) 58%);
  background-size: 100% 4px, auto;
}

body.is-mud {
  background:
    linear-gradient(rgba(255, 255, 255, 0.022) 50%, rgba(0, 0, 0, 0.045) 50%),
    radial-gradient(circle at 50% 0%, #10242d 0, var(--bg) 58%);
  background-size: 100% 4px, auto;
}

.shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: var(--app-height);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #0c1411;
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--line) 65%, transparent);
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 750;
  color: var(--accent-strong);
  text-shadow: none;
}

.mode-badge {
  display: inline-grid;
  place-items: center;
  min-height: 20px;
  margin-left: 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 0 7px;
  background: #07100d;
  color: var(--accent);
  font-size: 11px;
  line-height: 1;
  vertical-align: middle;
  text-shadow: none;
}

p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#terminal-subtitle {
  color: var(--accent);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

button,
.top-link {
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--button);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover,
.top-link:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--button) 72%, var(--accent) 14%);
}

.symbol-button {
  min-width: 64px;
  padding: 0 10px;
  font-size: 14px;
}

.font-controls,
.speed-controls {
  display: inline-grid;
  grid-template-columns: 36px minmax(48px, auto) 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #07100d;
  overflow: hidden;
}

.font-family-select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--button);
  color: var(--text);
  padding: 0 28px 0 10px;
  font: inherit;
  outline: none;
}

.font-family-select:focus {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.font-controls button,
.speed-controls button {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  font-size: 18px;
}

#font-size-badge,
#typewriter-speed-badge {
  display: inline-grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  color: var(--accent-strong);
  font-size: 13px;
  padding: 0 10px;
}

.console-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

body.has-quick-panel .console-layout {
  grid-template-columns: minmax(0, 1fr) 280px;
}

.terminal-frame {
  min-height: 0;
  padding: 12px;
  overflow: hidden;
  display: grid;
  place-items: stretch center;
}

body.has-quick-panel .terminal-frame {
  place-items: stretch end;
}

#terminal {
  width: 100%;
  max-width: calc(80ch + (22px * var(--xterm-scale)));
  height: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 50%, rgba(0, 0, 0, 0.045) 50%),
    #020403;
  background-size: 100% 4px, auto;
  box-shadow:
    0 0 0 1px #06130f,
    0 0 24px color-mix(in srgb, var(--accent) 16%, transparent),
    inset 0 0 24px color-mix(in srgb, var(--accent) 8%, transparent);
  font-size: var(--xterm-font-size);
}

body.is-mud #terminal {
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 50%, rgba(0, 0, 0, 0.05) 50%),
    #010607;
  background-size: 100% 4px, auto;
}

.xterm {
  height: 100%;
  padding: 16px;
  box-sizing: border-box;
}

.xterm-viewport {
  border-radius: 2px;
}

.xterm-screen {
  font-variant-ligatures: none;
}

.quick-panel {
  min-height: 0;
  border-left: 1px solid var(--line);
  padding: 12px;
  overflow: auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 50%, rgba(0, 0, 0, 0.045) 50%),
    color-mix(in srgb, var(--panel) 88%, #000 12%);
  background-size: 100% 4px, auto;
}

.quick-panel-title {
  color: var(--accent-strong);
  font-size: 15px;
  margin-bottom: 10px;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.direction-pad button,
.pad-center,
.quick-command-form button,
.quick-command-item button {
  min-height: 40px;
  padding: 0 8px;
}

.pad-center {
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  border-radius: 2px;
  color: var(--muted);
  background: #050908;
}

.quick-command-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  margin-bottom: 12px;
}

.quick-command-form input {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #020403;
  color: var(--text);
  padding: 0 10px;
  font-family: var(--xterm-font-family), var(--emoji-font-family), ui-monospace, monospace;
  font-size: 16px;
  outline: none;
}

.quick-command-form input:focus {
  border-color: var(--accent);
}

.quick-command-list {
  display: grid;
  gap: 6px;
}

.quick-command-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
}

.quick-command-item button:first-child {
  justify-content: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-command-remove {
  min-width: 34px;
  padding: 0;
  color: var(--muted);
}

#command-form {
  display: grid;
  grid-template-columns: minmax(0, calc(80ch + (22px * var(--xterm-scale)))) auto auto;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #0b1411;
}

#command {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #020403;
  color: var(--text);
  padding: 0 12px;
  font-family: var(--ui-font-family), var(--emoji-font-family), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: max(16px, var(--xterm-font-size));
  line-height: 1.2;
  outline: none;
}

#command:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

.command-shortcuts {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
}

.command-shortcuts button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--button-bg);
  color: var(--text);
  padding: 0 10px;
  font: 700 14px var(--xterm-font-family), var(--emoji-font-family), ui-monospace, monospace;
  cursor: pointer;
}

.command-shortcuts button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 720px) {
  .shell {
    height: var(--app-height);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  }

  h1 {
    font-size: 16px;
  }

  p {
    margin-top: 2px;
    font-size: 12px;
  }

  .actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  button,
  .top-link,
  .font-family-select {
    min-height: 30px;
    padding: 0 6px;
    font-size: 12px;
  }

  .symbol-button {
    min-width: 0;
    width: auto;
    padding: 0 6px;
    font-size: 12px;
  }

  .theme-select,
  .font-family-select {
    grid-column: span 2;
    width: 100%;
    min-width: 0;
    padding-left: 7px;
    padding-right: 20px;
  }

  .font-controls,
  .speed-controls {
    grid-column: span 2;
    grid-template-columns: 30px minmax(0, 1fr) 30px;
    min-height: 30px;
  }

  .font-controls button,
  .speed-controls button {
    min-height: 28px;
    font-size: 16px;
  }

  #font-size-badge,
  #typewriter-speed-badge {
    min-height: 28px;
    padding: 0 4px;
    font-size: 12px;
  }

  #command-form {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    padding: 8px calc(8px + env(safe-area-inset-right)) calc(8px + var(--safe-bottom)) calc(8px + env(safe-area-inset-left));
  }

  #command,
  #command-form > button {
    min-height: 38px;
    height: 38px;
  }

  .command-shortcuts {
    grid-column: 1 / -1;
    justify-content: stretch;
    margin-left: 0;
    gap: 5px;
  }

  .command-shortcuts button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 34px;
    height: 34px;
    padding: 0 4px;
    font-size: 12px;
  }

  body.has-quick-panel .console-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .terminal-frame {
    padding: 8px;
  }

  body.has-quick-panel .terminal-frame {
    place-items: stretch center;
  }

  #terminal {
    max-width: none;
  }

  .xterm {
    padding: 10px;
  }

  .quick-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: min(42dvh, 280px);
    padding: 8px;
  }

  .quick-panel-title {
    display: none;
  }

  .direction-pad {
    gap: 5px;
    margin-bottom: 8px;
  }

  .direction-pad button,
  .pad-center,
  .quick-command-form button,
  .quick-command-item button {
    min-height: 34px;
    padding: 0 5px;
    font-size: 12px;
  }

  .quick-command-form {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 5px;
    margin-bottom: 8px;
  }

  .quick-command-form input {
    min-height: 36px;
    font-size: 16px;
  }

  body.keyboard-open .topbar {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  body.keyboard-open .topbar p,
  body.keyboard-open .mode-badge,
  body.keyboard-open .command-shortcuts {
    display: none;
  }

  body.keyboard-open h1 {
    font-size: 14px;
  }

  body.keyboard-open .terminal-frame {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  body.keyboard-open #command-form {
    padding-top: 5px;
    padding-bottom: 5px;
  }
}
