:root {
  --ink: #1f2528;
  --muted: #677075;
  --panel: #f4f1e9;
  --cork: #b77b45;
  --cork-dark: #654126;
  --thread: #ab1f22;
  --thread-alt: #d06a2f;
  --paper: #fffaf0;
  --paper-blue: #eaf3f6;
  --paper-green: #eef7ea;
  --paper-red: #fff0ec;
  --paper-violet: #f2eefb;
  --line: rgba(31, 37, 40, 0.16);
  --shadow: 0 18px 44px rgba(42, 28, 18, 0.22);
  --focus: #204f64;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow: hidden;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #d8d1c3;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 30% 15%, rgba(255, 255, 255, 0.4), transparent 28%),
    linear-gradient(135deg, #d8d1c3, #8b735e);
}

.login-box {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid rgba(31, 37, 40, 0.14);
  border-radius: 10px;
  background: rgba(244, 241, 233, 0.96);
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin: 18px 0 8px;
}

.login-box p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.login-box label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  font-weight: 800;
}

.login-box input,
.field input,
.field textarea,
.field select,
.board-title,
.user-form input,
.user-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
}

.login-box input,
.field input,
.field select,
.board-title,
.user-form input,
.user-form select {
  min-height: 42px;
  padding: 8px 10px;
}

.form-error {
  min-height: 20px;
  margin-top: 12px;
  color: #942226;
  font-weight: 800;
}

.app {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  height: 100svh;
}

.left-panel,
.right-panel {
  min-width: 0;
  overflow: auto;
  padding: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent 180px), var(--panel);
  border-color: var(--line);
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.logo-mark {
  width: 58px;
  height: 38px;
  display: block;
  border: 2px solid rgba(31, 37, 40, 0.18);
  border-radius: 8px;
  object-fit: cover;
  object-position: center;
  background: #20262a;
  box-shadow: 0 8px 18px rgba(42, 28, 18, 0.16);
}

.user-box {
  display: grid;
  gap: 4px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.user-box span {
  color: var(--muted);
  font-size: 0.88rem;
}

.section-title {
  margin: 22px 0 10px;
  color: #384044;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tool-grid {
  display: grid;
  gap: 9px;
}

.tool-button,
.wide-button,
.icon-button,
.primary-button,
.text-button {
  min-height: 42px;
  border: 1px solid rgba(31, 37, 40, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
}

.primary-button,
.wide-button {
  padding: 9px 12px;
  font-weight: 850;
}

.primary-button {
  width: 100%;
  background: #20262a;
  color: #fff;
}

.text-button {
  width: fit-content;
  min-height: 32px;
  padding: 5px 8px;
  background: transparent;
  color: var(--focus);
  font-weight: 850;
}

.tool-button {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  text-align: left;
}

.tool-button span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: #fff;
  color: var(--focus);
  font-weight: 900;
}

.tool-button:hover,
.wide-button:hover,
.icon-button:hover,
.text-button:hover,
.wide-button.is-active {
  border-color: rgba(171, 31, 34, 0.4);
  background: #fff;
}

.wide-button {
  width: 100%;
}

.wide-button.danger {
  color: #942226;
}

.mini-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  min-width: 0;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 233, 0.96);
}

.board-title {
  flex: 1 1 220px;
  min-width: 160px;
  width: auto;
  font-weight: 900;
}

.top-actions {
  min-width: 0;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}

.top-actions .wide-button {
  flex: 0 0 auto;
  width: auto;
}

.icon-button {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  font-weight: 900;
}

.board-scroll {
  position: relative;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    #85705b;
  background-size: 36px 36px;
}

.board-frame {
  position: relative;
  margin: 0 auto;
  min-width: 0;
  min-height: 0;
}

.board {
  position: relative;
  width: 4200px;
  height: 2600px;
  margin: 0;
  overflow: hidden;
  border: 18px solid var(--cork-dark);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(87, 50, 25, 0.14) 1px, transparent 1px),
    linear-gradient(rgba(87, 50, 25, 0.14) 1px, transparent 1px),
    radial-gradient(circle at 20% 12%, rgba(255, 230, 180, 0.22), transparent 28%),
    var(--cork);
  background-size: 30px 30px, 30px 30px, auto, auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), var(--shadow);
  transform-origin: top left;
}

.threads {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.threads path {
  fill: none;
  stroke: var(--thread);
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: stroke;
  filter: drop-shadow(0 2px 1px rgba(54, 16, 11, 0.3));
  cursor: pointer;
}

.threads path.alt {
  stroke: var(--thread-alt);
}

.threads path.is-selected {
  stroke-width: 7;
}

.edge-label {
  fill: #321f16;
  paint-order: stroke;
  stroke: rgba(255, 250, 240, 0.85);
  stroke-width: 5px;
  font-size: 13px;
  font-weight: 850;
  pointer-events: none;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 360px;
  max-width: calc(100% - 80px);
  padding: 18px;
  border: 1px dashed rgba(47, 32, 20, 0.45);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.82);
  color: #4f3a28;
  line-height: 1.5;
  text-align: center;
  transform: translate(-50%, -50%);
}

.board-extend {
  position: absolute;
  z-index: 12;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid rgba(101, 65, 38, 0.28);
  border-radius: 50%;
  background: rgba(255, 250, 240, 0.92);
  color: #654126;
  box-shadow: 0 8px 18px rgba(59, 36, 18, 0.24);
  font-size: 1.4rem;
  font-weight: 900;
}

.board-extend:hover {
  background: #ffffff;
  border-color: rgba(171, 31, 34, 0.45);
  color: #ab1f22;
}

.board-extend-left {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.board-extend-right {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.board-extend-bottom {
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
}

.card {
  position: absolute;
  width: 214px;
  min-height: 142px;
  padding: 17px 14px 14px;
  border: 1px solid rgba(78, 53, 32, 0.18);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 14px 24px rgba(59, 36, 18, 0.22);
  cursor: grab;
  user-select: none;
}

.card:active {
  cursor: grabbing;
}

.card.is-selected {
  outline: 3px solid rgba(32, 79, 100, 0.35);
}

.card.is-connect-start {
  outline: 4px solid rgba(171, 31, 34, 0.42);
}

.card::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, transparent 13%), #cf2d2d;
  box-shadow: 0 5px 8px rgba(73, 24, 19, 0.28);
  transform: translateX(-50%);
}

.card[data-color="blue"] {
  background: var(--paper-blue);
}

.card[data-color="green"] {
  background: var(--paper-green);
}

.card[data-color="red"] {
  background: var(--paper-red);
}

.card[data-color="violet"] {
  background: var(--paper-violet);
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(31, 37, 40, 0.1);
  color: #2f3c43;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card h3 {
  margin: 10px 0 8px;
  font-size: 1.08rem;
  line-height: 1.15;
}

.card p {
  margin: 0;
  color: #4f5a60;
  font-size: 0.86rem;
  line-height: 1.42;
}

.panel-head,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.mobile-only {
  display: none;
}

.panel-head h2,
.dialog-head h2 {
  margin: 0 0 14px;
}

.inspector-empty,
.meta-box {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  line-height: 1.5;
}

.meta-box {
  display: grid;
  gap: 5px;
  margin-bottom: 13px;
  border-style: solid;
  font-size: 0.86rem;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: #384044;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.field textarea {
  min-height: 112px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.file-panel {
  display: grid;
  gap: 10px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.file-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.file-head h3 {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.file-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.file-panel input[type="file"] {
  width: 100%;
  min-height: 42px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}

.file-list {
  display: grid;
  gap: 10px;
}

.file-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.file-preview {
  max-width: 100%;
  max-height: 180px;
  border-radius: 6px;
  background: rgba(31, 37, 40, 0.08);
}

.file-item video {
  width: 100%;
}

.file-meta {
  min-width: 0;
}

.file-meta strong {
  display: block;
  overflow-wrap: anywhere;
}

.file-meta span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.file-actions a,
.file-actions button {
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--focus);
  text-decoration: none;
  font-weight: 850;
}

dialog {
  width: min(720px, calc(100% - 30px));
  max-height: min(720px, calc(100svh - 30px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(31, 37, 40, 0.38);
}

.audit-list,
.user-list,
.global-file-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
}

.audit-item,
.user-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.audit-item strong,
.user-item strong {
  display: block;
  margin-bottom: 4px;
}

.audit-item span,
.user-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

.user-form {
  display: grid;
  grid-template-columns: 1fr 1fr 140px 110px;
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 1120px) {
  .app {
    grid-template-columns: 240px minmax(0, 1fr);
    height: 100svh;
  }

  .right-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 20;
    max-height: min(62svh, 640px);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    transform: translateY(calc(100% + 24px));
    transition: transform 180ms ease;
  }

  .right-panel.has-selection {
    transform: translateY(0);
  }

  .mobile-only {
    display: inline-flex;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100svh;
    overflow: hidden;
  }

  .left-panel {
    max-height: 36svh;
    padding: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .left-panel .logo {
    display: none;
  }

  .user-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }

  .user-box .text-button {
    margin-left: auto;
  }

  .section-title {
    margin: 10px 0 7px;
    font-size: 0.68rem;
  }

  .tool-grid {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .tool-button {
    flex: 0 0 auto;
    min-width: 138px;
    min-height: 38px;
    padding: 6px 9px;
  }

  .wide-button {
    flex: 0 0 auto;
    width: auto;
    min-height: 38px;
    white-space: nowrap;
  }

  .mini-note {
    display: none;
  }

  .workspace {
    min-height: 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    padding: 9px 10px;
  }

  .board-title {
    flex: none;
    width: 100%;
    min-height: 38px;
  }

  .top-actions {
    max-width: 100%;
  }

  .top-actions .wide-button {
    flex: 0 0 auto;
  }

  .icon-button {
    flex: 0 0 auto;
    width: 40px;
    min-height: 38px;
  }

  .board-scroll {
    min-height: 0;
    padding: 10px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  .card {
    width: 190px;
    min-height: 132px;
    padding: 15px 12px 12px;
  }

  .card h3 {
    font-size: 1rem;
  }

  .card p {
    font-size: 0.8rem;
  }

  .right-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-height: 68svh;
    padding: 14px;
  }

  .panel-head h2,
  .dialog-head h2 {
    margin-bottom: 8px;
  }

  dialog {
    width: calc(100% - 16px);
    max-height: calc(100svh - 16px);
    padding: 14px;
  }

  .audit-list,
  .user-list,
  .global-file-list {
    max-height: calc(100svh - 170px);
  }

  .user-form {
    grid-template-columns: 1fr;
  }
}
