* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  color: var(--ink);
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 255, 255, 0.5) 0 30%, transparent 31%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  letter-spacing: 0.02em;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.8);
  backdrop-filter: blur(3px);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.topbar h1 {
  font-size: 24px;
  color: #3e2a14;
}

.lobby-badge {
  display: inline-flex;
  width: fit-content;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  color: var(--muted);
}

.auth-state {
  display: flex;
  align-items: center;
  gap: 10px;
}

.who {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  font-size: 13px;
}

.screen {
  flex: 1;
  min-height: 0;
}

.auth-screen {
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-card {
  width: min(620px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  animation: rise 0.35s ease both;
}

.auth-card p {
  color: var(--muted);
  margin: 8px 0 14px;
}

#app-screen {
  display: grid;
  grid-template-columns: 330px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.7);
  overflow: auto;
  padding: 16px;
}

.sidebar > h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: #4d3720;
}

.main-nav {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.nav-btn {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fffdf8;
  color: #3a2e22;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.nav-btn:hover {
  transform: translateX(2px);
  border-color: #b58f5f;
}

.nav-btn.active {
  background: #ffe4cc;
  border-color: #c78f55;
}

.content {
  overflow: auto;
  padding: 16px;
}

#view-root {
  animation: fadeIn 0.2s ease both;
}

.panel-card,
.page-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head.small h3 {
  font-size: 16px;
}

.page-grid {
  display: grid;
  gap: 12px;
}

.page-grid.two {
  grid-template-columns: 1.2fr 0.8fr;
}

.form-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

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

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

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

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

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #4d4136;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fffdf8;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff8ef;
  color: #3a2e22;
  cursor: pointer;
}

button:hover {
  border-color: #bb8f59;
}

.btn-primary {
  background: linear-gradient(135deg, #cf5b36, #af4525);
  border-color: #9d3d21;
  color: #fff;
}

.btn-mini {
  padding: 7px 10px;
  font-size: 13px;
}

.danger {
  background: #ffe7e7;
  color: #7f1a1a;
  border-color: #d1a4a4;
}

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

.hint {
  color: var(--muted);
  font-size: 12px;
}

.auth-message {
  margin-top: 10px;
  font-size: 13px;
  min-height: 20px;
}

.auth-message.success {
  color: var(--ok);
}

.auth-message.error {
  color: var(--bad);
}

.lobby-list {
  display: grid;
  gap: 8px;
}

.lobby-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fffdf8;
  padding: 10px;
}

.lobby-item.current {
  border-color: #c18649;
  box-shadow: 0 0 0 2px rgba(193, 134, 73, 0.2);
}

.lobby-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.attr-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.attr-grid.detail {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.attr-grid.detail div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 4px;
}

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

.status-grid > div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef8;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.status-grid span {
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  font-size: 14px;
}

.panel-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.kpi-grid > div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef8;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.kpi-grid span {
  color: var(--muted);
  font-size: 12px;
}

.kpi-grid strong {
  font-size: 14px;
}

.sheet-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 12px;
}

.sheet-main,
.sheet-side {
  display: grid;
  gap: 10px;
  align-content: start;
}

.sheet-side {
  border-left: 1px dashed var(--line);
  padding-left: 12px;
}

.bubble-list,
.repeat-list {
  display: grid;
  gap: 8px;
}

.bubble-row,
.repeat-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef8;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.bubble-row {
  background: #fff8ee;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.table-search {
  max-width: 420px;
}

.click-row {
  cursor: pointer;
}

.click-row:hover td {
  background: #fff3e4;
}

.selected-row td {
  background: #ffe8d2;
}

.tiny-thumb {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.subnav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.subnav button.active {
  background: #ffe4cc;
  border-color: #c78f55;
}

.map-board {
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fffef8;
  padding: 12px;
  min-height: 56px;
  margin-bottom: 10px;
}

.gm-map-stage {
  position: relative;
  width: 100%;
  min-height: 440px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-top: 10px;
  background:
    linear-gradient(180deg, rgba(163, 125, 83, 0.18), rgba(222, 201, 167, 0.22)),
    radial-gradient(circle at 18% 24%, rgba(255, 255, 255, 0.35), transparent 40%),
    radial-gradient(circle at 82% 72%, rgba(255, 255, 255, 0.28), transparent 42%),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(122, 93, 60, 0.1) 32px),
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(122, 93, 60, 0.1) 32px),
    linear-gradient(145deg, #dac29f, #ccb48f);
}

.gm-map-stage-head {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 1;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(120, 85, 47, 0.45);
  background: rgba(255, 250, 241, 0.84);
  color: #6a4c2e;
  font-size: 12px;
}

.gm-map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid #7d5331;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 2px 7px rgba(48, 27, 10, 0.28);
  z-index: 2;
}

.gm-map-marker.place {
  background: linear-gradient(145deg, #b76f39, #90481f);
}

.gm-map-marker.trader {
  background: linear-gradient(145deg, #2e7b7a, #1d5759);
}

.gm-map-marker.active {
  box-shadow: 0 0 0 2px rgba(255, 249, 232, 0.9), 0 0 0 5px rgba(108, 72, 39, 0.45);
}

.tag-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fffdf8;
  font-size: 12px;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
}

.result-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef8;
  padding: 10px;
  min-height: 44px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef8;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 8px;
  font-size: 13px;
  vertical-align: top;
}

th {
  font-family: "Palatino Linotype", Georgia, serif;
  color: #4b3824;
  background: #f7ebd9;
  position: sticky;
  top: 0;
}

.ok {
  color: var(--ok);
  font-weight: 700;
}

.bad {
  color: var(--bad);
  font-weight: 700;
}

.floating-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.floating-window {
  position: fixed;
  pointer-events: auto;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid #af875e;
  border-radius: 12px;
  box-shadow: 0 24px 54px rgba(45, 26, 8, 0.28);
  background: #fff8ed;
  overflow: hidden;
}

.floating-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, #f3d5b0, #e8bc8f);
  cursor: move;
}

.btn-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid #a36a3f;
  background: #df8962;
  color: #fff;
  font-weight: 700;
}

.floating-body {
  overflow: auto;
  padding: 12px;
}

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

@keyframes rise {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 1100px) {
  #app-screen {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .page-grid.two,
  .form-grid.four,
  .form-grid.three,
  .form-grid.two,
  .attr-grid,
  .attr-grid.detail,
  .kpi-grid,
  .status-grid,
  .sheet-layout {
    grid-template-columns: 1fr;
  }

  .sheet-side {
    border-left: 0;
    padding-left: 0;
  }

  .floating-window {
    width: min(92vw, 560px) !important;
    height: min(80vh, 620px) !important;
    left: 4vw !important;
    top: 10vh !important;
  }
}
