:root {
  --ink: #1f1a14;
  --parchment: #ecdfc5;
  --parchment-deep: #d9c6a0;
  --sea: #173a43;
  --sea-shadow: #0f262d;
  --brass: #b58f4f;
  --brass-soft: #ceb077;
  --panel-text: #f5f0e4;
  --action: #7f2c1d;
  --action-hover: #a13a24;
  --surface: #e9dcc3;
  --top-bar-height: 112px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IM Fell English", Georgia, serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(181, 143, 79, 0.2), transparent 30%),
    radial-gradient(circle at 90% 15%, rgba(23, 58, 67, 0.35), transparent 34%),
    linear-gradient(145deg, #f5ecd9 0%, var(--parchment) 35%, var(--parchment-deep) 100%);
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.1;
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 38px 38px;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  margin-top: var(--top-bar-height);
  min-height: calc(100vh - var(--top-bar-height));
}

.control-panel {
  background:
    linear-gradient(180deg, rgba(28, 64, 72, 0.97), rgba(16, 38, 45, 0.97)),
    radial-gradient(circle at top, rgba(206, 176, 119, 0.2), transparent 45%);
  color: var(--panel-text);
  padding: 1.1rem 1rem;
  border-right: 4px solid var(--brass);
  box-shadow: inset -1px 0 0 rgba(245, 240, 228, 0.12);
  height: calc(100vh - var(--top-bar-height));
  overflow: auto;
  position: relative;
}

.home-link {
  display: inline-block;
  margin-bottom: 0.75rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(206, 176, 119, 0.45);
  color: #f4e8d0;
  text-decoration: none;
  font-family: "Cinzel", "Times New Roman", serif;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  background: rgba(7, 18, 22, 0.2);
}

.home-link:hover {
  background: rgba(206, 176, 119, 0.2);
}

h1 {
  margin-top: 0;
  margin-bottom: 0.35rem;
  letter-spacing: 0.04em;
  font-family: "Cinzel", "Times New Roman", serif;
  font-weight: 700;
  color: #f7e7c9;
}

.subtitle {
  margin: 0 0 1rem;
  font-size: 0.86rem;
  color: #d8c9a7;
  letter-spacing: 0.04em;
}

.panel-tip {
  margin: 0 0 0.9rem;
  font-size: 0.78rem;
  color: #d7c49f;
  border: 1px dashed rgba(206, 176, 119, 0.4);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: rgba(9, 20, 24, 0.28);
}

.initiative-panel {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 7;
  min-height: var(--top-bar-height);
  border-bottom: 2px solid rgba(206, 176, 119, 0.45);
  padding: 0.48rem 0.72rem 0.52rem;
  display: grid;
  grid-template-columns: 84px minmax(240px, 360px) minmax(300px, 420px) 1fr;
  gap: 0.55rem;
  align-items: center;
  background:
    linear-gradient(180deg, rgba(10, 22, 26, 0.95), rgba(9, 20, 24, 0.93)),
    radial-gradient(circle at top, rgba(206, 176, 119, 0.12), transparent 45%);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

.initiative-panel h2 {
  margin: 0;
  font-size: 0.93rem;
  font-family: "Cinzel", "Times New Roman", serif;
  color: #f2dfbb;
  text-align: center;
}

.initiative-add {
  display: grid;
  grid-template-columns: 1fr 68px 62px;
  gap: 0.4rem;
  margin: 0;
}

.initiative-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 0;
}

.initiative-actions button {
  margin-bottom: 0;
  padding: 0.4rem 0.35rem;
  font-size: 0.78rem;
}

.initiative-current {
  margin: 0;
  font-size: 0.76rem;
  color: #e6d5b3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.initiative-track {
  min-width: 0;
}

.initiative-list {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border-top: none;
  border-left: 1px solid rgba(206, 176, 119, 0.3);
  padding: 0 0 0 0.6rem;
}

.initiative-item {
  display: flex;
  align-items: center;
  gap: 0.24rem;
  margin-bottom: 0;
  flex-shrink: 0;
}

.initiative-item button {
  margin-bottom: 0;
}

.initiative-label {
  flex: 0 0 auto;
  text-align: left;
  background: rgba(244, 235, 217, 0.9);
  color: #271f16;
  border: 1px solid rgba(206, 176, 119, 0.35);
  border-radius: 7px;
  padding: 0.34rem 0.48rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.initiative-item.active .initiative-label {
  background: rgba(206, 176, 119, 0.92);
  color: #1f180e;
  border-color: rgba(255, 240, 206, 0.7);
}

.initiative-remove {
  width: 30px;
  padding: 0.34rem 0;
  font-size: 0.74rem;
}

.notes-drawer {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 8;
  display: flex;
  align-items: stretch;
  flex-direction: row-reverse;
}

.notes-toggle {
  width: 42px;
  border-radius: 10px 0 0 10px;
  margin: 0;
  writing-mode: vertical-rl;
  transform: none;
  letter-spacing: 0.06em;
  min-height: 132px;
}

.notes-panel {
  width: 280px;
  background: linear-gradient(180deg, rgba(21, 44, 51, 0.97), rgba(11, 27, 33, 0.97));
  border: 2px solid rgba(206, 176, 119, 0.62);
  border-right: none;
  border-radius: 12px 0 0 12px;
  padding: 0.65rem 0.65rem 0.72rem;
  color: #f1e5ca;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
}

.notes-panel h2 {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
  font-family: "Cinzel", "Times New Roman", serif;
}

#notesText {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid rgba(206, 176, 119, 0.4);
  padding: 0.55rem;
  font-family: "IM Fell English", Georgia, serif;
  background: rgba(249, 240, 223, 0.95);
  color: #2a2218;
}

.notes-drawer.collapsed .notes-panel {
  display: none;
}

.panel-group {
  border: 1px solid rgba(206, 176, 119, 0.34);
  border-radius: 10px;
  margin-bottom: 0.9rem;
  background: linear-gradient(180deg, rgba(8, 16, 19, 0.22), rgba(8, 16, 19, 0.1));
  backdrop-filter: blur(1px);
  overflow: hidden;
}

.panel-group summary {
  list-style: none;
  cursor: pointer;
  padding: 0.72rem 0.75rem;
  font-size: 0.96rem;
  font-family: "Cinzel", "Times New Roman", serif;
  color: #f1deb7;
  letter-spacing: 0.03em;
  background: rgba(5, 15, 18, 0.28);
  border-bottom: 1px solid rgba(206, 176, 119, 0.28);
}

.panel-group summary::-webkit-details-marker {
  display: none;
}

.panel-group summary::after {
  content: "▸";
  float: right;
  transition: transform 120ms ease;
}

.panel-group[open] summary::after {
  transform: rotate(90deg);
}

.panel-body {
  padding: 0.72rem 0.75rem 0.78rem;
}

.control-row {
  display: block;
  margin-bottom: 0.35rem;
  color: #f0e1c3;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.25rem 0 0.55rem;
  font-weight: 600;
}

.check-row input {
  width: auto;
  margin: 0;
}

.readout {
  margin: 0.3rem 0 0.5rem;
  font-weight: 600;
  color: #e9d9b8;
}

button,
input[type="text"],
input[type="file"],
input[type="range"],
input[type="color"],
select {
  width: 100%;
  margin-bottom: 0.5rem;
}

button,
select,
input[type="text"],
input[type="file"] {
  border-radius: 7px;
  padding: 0.5rem 0.65rem;
  border: 1px solid rgba(206, 176, 119, 0.35);
  background: rgba(244, 235, 217, 0.9);
  color: #2a2218;
  font-family: "IM Fell English", Georgia, serif;
}

button {
  background: var(--action);
  color: #fff7eb;
  font-weight: 700;
  cursor: pointer;
  border-color: rgba(255, 231, 196, 0.25);
  text-transform: none;
  transition: background 120ms ease, transform 120ms ease;
}

button:hover {
  background: var(--action-hover);
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.token-creator {
  display: grid;
  grid-template-columns: 1fr 54px 54px;
  gap: 0.5rem;
}

.token-list {
  max-height: 220px;
  overflow: auto;
  border-top: 1px solid rgba(206, 176, 119, 0.35);
  padding-top: 0.5rem;
}

.token-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid transparent;
  color: #f4e8d0;
}

.token-item.selected {
  background: rgba(181, 143, 79, 0.24);
  border-color: rgba(206, 176, 119, 0.55);
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.swatch.image {
  background-size: cover;
  background-position: center;
}

.map-stage {
  display: grid;
  place-items: center;
  padding: 1.2rem;
}

canvas {
  width: min(100%, 1200px);
  height: auto;
  border: 4px solid #8d7348;
  border-radius: 12px;
  background: var(--surface);
  box-shadow:
    0 14px 34px rgba(16, 24, 27, 0.32),
    inset 0 0 0 2px rgba(245, 233, 206, 0.55);
}

select:focus,
button:focus,
input:focus {
  outline: 2px solid var(--brass-soft);
  outline-offset: 1px;
}

@media (max-width: 960px) {
  :root {
    --top-bar-height: 170px;
  }

  .initiative-panel {
    grid-template-columns: 1fr;
    gap: 0.38rem;
    align-items: stretch;
    padding: 0.42rem 0.55rem 0.52rem;
  }

  .initiative-panel h2 {
    text-align: left;
  }

  .initiative-list {
    border-left: none;
    border-top: 1px solid rgba(206, 176, 119, 0.3);
    padding: 0.45rem 0 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: none;
    border-bottom: 4px solid var(--brass);
    height: auto;
    max-height: 52vh;
  }

  .notes-panel {
    width: 240px;
  }
}
