:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --soft: #86868b;
  --page: #f5f5f7;
  --line: rgba(0, 0, 0, 0.12);
  --hairline: rgba(0, 0, 0, 0.08);
  --material: rgba(255, 255, 255, 0.68);
  --material-strong: rgba(255, 255, 255, 0.86);
  --material-line: rgba(0, 0, 0, 0.08);
  --filter: saturate(170%) blur(24px);
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --red: #ff3b30;
  --green: #30d158;
  --orange: #ff9f0a;
  --pane: rgba(251, 251, 253, 0.72);
  --field: rgba(255, 255, 255, 0.9);
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f5f5f7;
  --muted: #a1a1a6;
  --soft: #8e8e93;
  --page: #202124;
  --line: rgba(255, 255, 255, 0.16);
  --hairline: rgba(255, 255, 255, 0.1);
  --material: rgba(52, 54, 59, 0.68);
  --material-strong: rgba(62, 64, 70, 0.86);
  --material-line: rgba(255, 255, 255, 0.1);
  --filter: saturate(170%) blur(24px);
  --blue: #0a84ff;
  --blue-hover: #409cff;
  --pane: rgba(36, 37, 42, 0.72);
  --field: rgba(28, 29, 34, 0.84);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 25% -15%, rgba(255, 255, 255, 0.92), transparent 34%),
    radial-gradient(circle at 84% 10%, rgba(0, 113, 227, 0.14), transparent 28%),
    radial-gradient(circle at 12% 92%, rgba(48, 209, 88, 0.1), transparent 26%),
    var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 22% -16%, rgba(90, 92, 104, 0.52), transparent 34%),
    radial-gradient(circle at 84% 10%, rgba(10, 132, 255, 0.16), transparent 28%),
    radial-gradient(circle at 12% 92%, rgba(48, 209, 88, 0.08), transparent 26%),
    var(--page);
}

button,
input,
select {
  font: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--material-line);
  border-radius: 999px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--material-strong);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.62) inset;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

button:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.94);
}

:root[data-theme="dark"] button:not(:disabled):hover {
  background: rgba(76, 78, 86, 0.94);
}

button:not(:disabled):active {
  transform: scale(0.985);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

button.primary {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
  box-shadow: none;
}

button.primary:hover {
  background: var(--blue-hover);
}

button.danger {
  border-color: rgba(255, 59, 48, 0.32);
  color: var(--red);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  background: rgba(251, 251, 253, 0.78);
  -webkit-backdrop-filter: var(--filter);
  backdrop-filter: var(--filter);
}

:root[data-theme="dark"] .topbar {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(32, 33, 36, 0.78);
}

.brand {
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 16px;
  color: rgba(29, 29, 31, 0.78);
  font-size: 12px;
}

:root[data-theme="dark"] .topnav {
  color: rgba(245, 245, 247, 0.78);
}

.nav-tool,
.nav-link {
  min-height: 28px;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  box-shadow: none;
  font-size: inherit;
}

.nav-tool.is-active {
  color: var(--ink);
  font-weight: 700;
}

.app-shell {
  width: min(1240px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.login-shell {
  min-height: calc(100vh - 130px);
  display: grid;
  place-items: center;
}

.login-card,
.dashboard-surface,
.terminal-surface,
.world-surface,
.settings-surface,
.users-surface,
.tool-card {
  border: 1px solid rgba(255, 255, 255, 0.46);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.28)),
    rgba(255, 255, 255, 0.34);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  backdrop-filter: saturate(190%) blur(30px);
}

:root[data-theme="dark"] .login-card,
:root[data-theme="dark"] .dashboard-surface,
:root[data-theme="dark"] .terminal-surface,
:root[data-theme="dark"] .world-surface,
:root[data-theme="dark"] .settings-surface,
:root[data-theme="dark"] .users-surface,
:root[data-theme="dark"] .tool-card {
  border-color: rgba(255, 255, 255, 0.14);
  background:
    linear-gradient(180deg, rgba(78, 80, 88, 0.58), rgba(35, 36, 42, 0.36)),
    rgba(40, 42, 48, 0.52);
}

.login-card {
  width: min(420px, 100%);
  border-radius: 30px;
  padding: 30px;
}

.login-card h1,
.home-head h1,
h2,
p {
  margin: 0;
}

.login-card h1 {
  font-size: 38px;
  line-height: 1.05;
  margin-bottom: 22px;
}

.login-form,
.settings-form,
.user-form,
.upload-form,
.command-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--field);
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(0, 113, 227, 0.62);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

.home-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
  margin-bottom: 18px;
}

.home-head h1 {
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--orange);
  font-size: 13px;
  font-weight: 750;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
}

.pill.online {
  color: #0b6f37;
  background: rgba(48, 209, 88, 0.16);
}

.pill.offline {
  color: var(--red);
  background: rgba(255, 59, 48, 0.14);
}

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

.tool-card {
  min-height: 78px;
  border-radius: 22px;
  justify-content: flex-start;
  gap: 12px;
  padding: 14px;
  text-align: left;
}

.tool-card.is-active {
  border-color: rgba(0, 113, 227, 0.34);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 16px 34px rgba(0, 113, 227, 0.14);
}

.tool-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(160deg, #1d1d1f, #5d5d62);
}

.icon-status::before,
.icon-terminal::before,
.icon-world::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  border: 2px solid #fff;
  border-radius: 50%;
}

.icon-terminal {
  background: linear-gradient(160deg, #111, #3a3a40);
}

.icon-terminal::before {
  width: 22px;
  height: 14px;
  border-radius: 4px;
}

.icon-world {
  background: linear-gradient(160deg, #24c6dc, #30d158);
}

.tool-card strong,
.tool-card small {
  display: block;
}

.tool-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.panel[hidden] {
  display: none;
}

.dashboard-surface,
.terminal-surface,
.world-surface,
.settings-surface,
.users-surface {
  display: grid;
  grid-template-columns: minmax(318px, 420px) minmax(0, 1fr);
  min-height: 610px;
  overflow: hidden;
  border-radius: 30px;
}

.metric-pane,
.command-pane,
.world-pane,
.settings-pane,
.users-pane {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--material-line);
  background: rgba(255, 255, 255, 0.42);
}

:root[data-theme="dark"] .metric-pane,
:root[data-theme="dark"] .command-pane,
:root[data-theme="dark"] .world-pane,
:root[data-theme="dark"] .settings-pane,
:root[data-theme="dark"] .users-pane {
  background: rgba(28, 29, 34, 0.36);
}

.info-pane,
.terminal-pane,
.upload-pane,
.user-edit-pane {
  min-width: 0;
  padding: 24px 28px;
  background: var(--pane);
}

.section-title h2,
.preview-head h2,
.command-pane h2,
.upload-pane h2,
.settings-pane h2,
.users-pane h2,
.user-edit-pane h2 {
  font-size: 24px;
  line-height: 1.12;
}

.metrics {
  display: grid;
  gap: 10px;
}

.metric,
.detail-list div,
.settings-form label,
.user-form label,
.permission-grid,
.check-row,
.file-drop {
  border: 1px solid var(--material-line);
  border-radius: 18px;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.52);
}

:root[data-theme="dark"] .metric,
:root[data-theme="dark"] .detail-list div,
:root[data-theme="dark"] .settings-form label,
:root[data-theme="dark"] .user-form label,
:root[data-theme="dark"] .permission-grid,
:root[data-theme="dark"] .check-row,
:root[data-theme="dark"] .file-drop {
  background: rgba(58, 60, 66, 0.46);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 28px;
  line-height: 1.05;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: auto;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  min-height: 92px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--material-line);
}

.preview-head span {
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.045);
  font-size: 13px;
  font-weight: 700;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: 22px 0 0;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
  font-weight: 750;
  text-align: right;
}

.terminal-surface {
  grid-template-columns: minmax(0, 1fr) minmax(318px, 380px);
}

.terminal-pane {
  padding: 22px;
}

.terminal-window {
  min-height: 558px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: #101114;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.28);
}

.terminal-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px;
  color: rgba(245, 245, 247, 0.72);
  background: #1c1d21;
  font: 12px/1 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

.terminal-titlebar strong {
  margin-left: 6px;
  font-weight: 650;
}

.traffic {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.traffic.red { background: #ff5f57; }
.traffic.yellow { background: #febc2e; }
.traffic.green { background: #28c840; }

.terminal-output {
  min-height: 528px;
  max-height: 66vh;
  overflow: auto;
  margin: 0;
  padding: 13px 14px 18px;
  color: #d8dee9;
  font: 12px/1.45 "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.quick-commands {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-commands button {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.quiet {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.world-list,
.users-list {
  display: grid;
  gap: 10px;
}

.world-item,
.user-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--material-line);
  border-radius: 18px;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.52);
}

:root[data-theme="dark"] .world-item,
:root[data-theme="dark"] .user-item {
  background: rgba(58, 60, 66, 0.46);
}

.world-item strong,
.user-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.world-item span,
.user-item span {
  color: var(--muted);
  font-size: 12px;
}

.file-drop {
  min-height: 124px;
  justify-content: center;
  text-align: center;
  cursor: pointer;
}

.file-drop input {
  display: none;
}

.settings-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-form button,
.user-form button {
  justify-self: start;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input,
.permission-grid input {
  width: auto;
  min-height: 0;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.permission-grid legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--material-line);
  border-radius: 18px;
  padding: 12px 16px;
  color: var(--ink);
  background: var(--material-strong);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--filter);
  backdrop-filter: var(--filter);
  font-size: 13px;
  font-weight: 650;
}

@media (prefers-reduced-motion: no-preference) {
  :root[data-motion="on"] .app-shell {
    animation: page-enter 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }

  :root[data-motion="on"] .panel.is-active {
    animation: panel-enter 190ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }

  @keyframes page-enter {
    from { opacity: 0; transform: scale(0.985); filter: blur(8px); }
    to { opacity: 1; transform: scale(1); filter: blur(0); }
  }

  @keyframes panel-enter {
    from { opacity: 0; transform: translateY(8px) scale(0.992); filter: blur(6px); }
    to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
  }
}

@media (max-width: 980px) {
  .dashboard-surface,
  .terminal-surface,
  .world-surface,
  .settings-surface,
  .users-surface {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .metric-pane,
  .command-pane,
  .world-pane,
  .settings-pane,
  .users-pane {
    border-right: 0;
    border-bottom: 1px solid var(--material-line);
  }
}

@media (max-width: 640px) {
  body {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    min-height: calc(64px + env(safe-area-inset-bottom));
    justify-content: center;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--hairline);
    border-bottom: 0;
  }

  .brand {
    display: none;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: min(100%, 520px);
    gap: 4px;
    border: 1px solid var(--hairline);
    border-radius: 28px;
    padding: 5px;
    background: rgba(255, 255, 255, 0.68);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.72) inset, 0 14px 28px rgba(0, 0, 0, 0.08);
  }

  :root[data-theme="dark"] .topnav {
    background: rgba(46, 48, 54, 0.72);
  }

  .nav-tool,
  .nav-link {
    min-height: 42px;
    border-radius: 23px;
    font-size: 11px;
  }

  .nav-tool.is-active {
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.76) inset, 0 6px 14px rgba(0, 0, 0, 0.08);
  }

  :root[data-theme="dark"] .nav-tool.is-active {
    background: rgba(78, 80, 88, 0.92);
  }

  .app-shell {
    width: min(calc(100vw - 20px), 560px);
    padding-top: 14px;
  }

  .home-head,
  .tool-grid,
  .settings-form,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .home-head h1 {
    font-size: 34px;
  }

  .metric-pane,
  .command-pane,
  .world-pane,
  .settings-pane,
  .users-pane,
  .info-pane,
  .terminal-pane,
  .upload-pane,
  .user-edit-pane {
    padding: 16px;
  }

  .dashboard-surface,
  .terminal-surface,
  .world-surface,
  .settings-surface,
  .users-surface {
    border-radius: 24px;
  }
}
