:root {
  --bg: #edf0ec;
  --surface: #fbfaf6;
  --surface-2: #f3f0e7;
  --line: #d7d0c1;
  --ink: #1f2528;
  --muted: #677070;
  --water: #3a9bb2;
  --water-deep: #1d6f88;
  --harbor: #24566b;
  --shadow: 0 14px 36px rgba(39, 43, 45, 0.12);
  --radius: 8px;
  --p-a: #d9505b;
  --p-b: #2f77c9;
  --p-c: #278860;
  --p-d: #8b5bc8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(58, 155, 178, 0.16), transparent 34%),
    linear-gradient(210deg, rgba(217, 80, 91, 0.10), transparent 28%),
    var(--bg);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #bbb4a6;
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--ink);
  padding: 0 12px;
  font-size: 16px;
}

input:focus {
  border-color: var(--water-deep);
  outline: 2px solid rgba(29, 111, 136, 0.2);
  outline-offset: 1px;
}

[hidden] {
  display: none !important;
}

button {
  min-height: 38px;
  border: 1px solid #bbb4a6;
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: #81786b;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

select {
  min-height: 38px;
  border: 1px solid #bbb4a6;
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--ink);
  padding: 0 10px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  padding: 16px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(190px, 260px) 1fr auto;
  gap: 14px;
  align-items: center;
  max-width: 1480px;
  margin: 0 auto 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  position: relative;
  width: 48px;
  height: 48px;
  border: 2px solid #1f2528;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent 44%, var(--water) 44%, var(--water) 56%, transparent 56%),
    linear-gradient(0deg, transparent 44%, var(--water) 44%, var(--water) 56%, transparent 56%),
    #fff9ee;
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.75);
}

.brand-mark span {
  position: absolute;
  inset: 15px;
  border-radius: 50%;
  background: var(--harbor);
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1;
}

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

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

.status-item {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 250, 246, 0.78);
}

.status-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-item strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.select-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.top-actions button {
  padding: 0 16px;
  background: #1f2528;
  color: #fffdf8;
  border-color: #1f2528;
}

.connection-status,
.room-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf8;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.connection-status.is-online::before,
.connection-status.is-connecting::before,
.connection-status.is-offline::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #278860;
}

.connection-status.is-connecting::before {
  background: #d09a30;
}

.connection-status.is-offline::before {
  background: #d9505b;
}

.room-chip {
  color: var(--ink);
  letter-spacing: 1px;
}

.lobby-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: auto;
  background:
    linear-gradient(135deg, rgba(58, 155, 178, 0.22), transparent 42%),
    linear-gradient(210deg, rgba(217, 80, 91, 0.12), transparent 36%),
    var(--bg);
}

.lobby {
  width: min(460px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 250, 246, 0.96);
  box-shadow: 0 24px 70px rgba(31, 37, 40, 0.18);
}

.lobby-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.lobby-brand p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.lobby-brand h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1;
}

.lobby-entry {
  display: grid;
  gap: 10px;
}

.lobby-entry label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.primary-button {
  min-height: 46px;
  background: #1f2528;
  color: #fffdf8;
  border-color: #1f2528;
}

.text-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.lobby-divider {
  position: relative;
  margin: 4px 0;
  border-top: 1px solid var(--line);
  text-align: center;
}

.lobby-divider span {
  position: relative;
  top: -10px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 8px;
}

#roomCodeInput {
  letter-spacing: 3px;
  text-transform: uppercase;
  font-weight: 900;
}

.room-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.room-heading span,
.room-heading strong {
  display: block;
}

.room-heading span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.room-heading strong {
  font-size: 28px;
  letter-spacing: 3px;
}

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

.lobby-seat {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 50px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.lobby-seat strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-seat small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.lobby-seat.is-connected small {
  color: #278860;
}

.seat-token {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
}

.player-a { background: var(--p-a); }
.player-b { background: var(--p-b); }
.player-c { background: var(--p-c); }
.player-d { background: var(--p-d); }

.lobby-message {
  min-height: 20px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.lobby-room .primary-button {
  width: 100%;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 24px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #1f2528;
  color: #fffdf8;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(460px, 1fr) minmax(270px, 340px);
  gap: 14px;
  max-width: 1480px;
  margin: 0 auto;
}

.panel,
.center-stage {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 250, 246, 0.86);
  box-shadow: var(--shadow);
}

.panel {
  min-height: 0;
  overflow: hidden;
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
}

.score-section,
.log-section,
.market-section,
.project-section {
  min-height: 0;
  padding: 12px;
}

.score-section,
.market-section {
  border-bottom: 1px solid var(--line);
}

.log-section,
.project-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}

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

.section-title h2 {
  margin: 0;
  font-size: 13px;
  line-height: 1;
  text-transform: uppercase;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

#compactLogButton {
  width: 34px;
  min-height: 32px;
  padding: 0;
}

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

.score-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.score-row.is-current {
  border-color: #1f2528;
  box-shadow: inset 0 0 0 1px #1f2528;
}

.player-dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
}

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

.score-meta strong {
  display: block;
  font-size: 14px;
}

.score-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.score-points {
  font-size: 21px;
  font-weight: 900;
}

.game-log {
  flex: 1;
  min-height: 170px;
  max-height: calc(100vh - 360px);
  margin: 0;
  padding: 0 0 0 20px;
  overflow: auto;
  color: #394144;
  font-size: 12px;
  line-height: 1.42;
}

.game-log.compact li:nth-child(n + 9) {
  display: none;
}

.game-log li {
  margin-bottom: 6px;
}

.center-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 720px;
  padding: 12px;
}

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

.tide-card {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.tide-card:first-child {
  border-color: var(--water-deep);
  box-shadow: inset 0 0 0 1px var(--water-deep);
}

.tide-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.tide-card strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 10px;
  border: 1px solid #c8d6d4;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(29, 111, 136, 0.10) 1px, transparent 1px),
    linear-gradient(0deg, rgba(29, 111, 136, 0.10) 1px, transparent 1px),
    #e7f0ee;
  background-size: 34px 34px;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr));
  gap: 6px;
  width: min(100%, 660px);
  aspect-ratio: 1;
}

.cell {
  position: relative;
  display: grid;
  place-items: stretch;
  min-width: 0;
  min-height: 0;
  border: 1px dashed rgba(31, 37, 40, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.58);
  overflow: hidden;
}

.cell.is-legal {
  border-style: solid;
  border-color: #1f2528;
  background: rgba(255, 253, 248, 0.92);
  cursor: pointer;
}

.cell.is-legal:hover {
  box-shadow: inset 0 0 0 3px rgba(31, 37, 40, 0.15);
}

.cell.is-tide-line::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(58, 155, 178, 0.16);
}

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(31, 37, 40, 0.22);
  border-radius: var(--radius);
  background: var(--tile-color, #fffdf8);
  overflow: hidden;
}

.tile.harbor {
  background:
    radial-gradient(circle at 50% 50%, #fffdf8 0 12%, transparent 13%),
    linear-gradient(90deg, transparent 44%, var(--water) 44%, var(--water) 56%, transparent 56%),
    linear-gradient(0deg, transparent 44%, var(--water) 44%, var(--water) 56%, transparent 56%),
    var(--harbor);
  color: #fff;
}

.tile-label {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 3;
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.88);
  color: #1f2528;
  font-size: 13px;
  font-weight: 900;
}

.tile.harbor .tile-label {
  background: rgba(31, 37, 40, 0.78);
  color: #fff;
}

.tile-shape {
  position: absolute;
  right: 6px;
  top: 7px;
  z-index: 3;
  color: rgba(31, 37, 40, 0.58);
  font-size: 11px;
  font-weight: 900;
}

.canal-center,
.canal-arm {
  position: absolute;
  z-index: 1;
  background: linear-gradient(180deg, #63bfd0, var(--water-deep));
}

.canal-center {
  top: 39%;
  left: 39%;
  width: 22%;
  height: 22%;
  border-radius: 50%;
}

.canal-arm.n,
.canal-arm.s {
  left: 44%;
  width: 12%;
  height: 43%;
}

.canal-arm.n {
  top: 0;
}

.canal-arm.s {
  bottom: 0;
}

.canal-arm.e,
.canal-arm.w {
  top: 44%;
  width: 43%;
  height: 12%;
}

.canal-arm.e {
  right: 0;
}

.canal-arm.w {
  left: 0;
}

.marker-stack {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 4;
  display: flex;
  flex-direction: row-reverse;
  gap: 2px;
}

.marker {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid #fffdf8;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  box-shadow: 0 2px 5px rgba(31, 37, 40, 0.28);
}

.defense-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid #8c6c21;
  border-radius: 50%;
  background: #f6ce63;
  color: #3b321a;
  font-size: 12px;
  font-weight: 900;
}

.action-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.selection-status {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

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

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

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

#rotateButton {
  width: 42px;
  padding: 0;
  font-size: 22px;
}

.market-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.market-card {
  position: relative;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  cursor: pointer;
}

.market-card:hover:not(.is-disabled) {
  border-color: #1f2528;
}

.market-card.is-selected {
  border-color: #1f2528;
  box-shadow: inset 0 0 0 1px #1f2528;
}

.market-card.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.market-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.market-mini {
  aspect-ratio: 1;
}

.market-mini .tile-label {
  top: 4px;
  left: 4px;
  min-width: 22px;
  height: 20px;
  font-size: 11px;
}

.market-mini .tile-shape {
  display: none;
}

.market-mini .marker-stack,
.market-mini .defense-badge {
  display: none;
}

.project-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  max-height: calc(100vh - 320px);
  padding-right: 2px;
}

.project-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.project-card.is-claimable {
  border-color: #1f2528;
  box-shadow: inset 0 0 0 1px #1f2528;
}

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

.project-head strong {
  font-size: 14px;
}

.project-head span {
  font-size: 16px;
  font-weight: 900;
}

.project-card p {
  margin: 0;
  color: #4e5658;
  font-size: 12px;
  line-height: 1.35;
}

.project-card button {
  width: 100%;
  min-height: 34px;
  background: #1f2528;
  color: #fffdf8;
  border-color: #1f2528;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 37, 40, 0.46);
}

.result-modal {
  width: min(520px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(31, 37, 40, 0.32);
}

.result-modal h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.result-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.result-row:last-of-type {
  border-bottom: 0;
}

.result-row strong {
  display: block;
}

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

.result-row b {
  font-size: 24px;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.result-actions button {
  padding: 0 16px;
  background: #1f2528;
  color: #fffdf8;
  border-color: #1f2528;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

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

  .top-actions {
    justify-content: flex-start;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .center-stage {
    min-height: auto;
    order: -1;
  }

  .left-panel,
  .right-panel {
    min-height: auto;
  }

  .project-list,
  .game-log {
    max-height: 280px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .action-bar {
    grid-template-columns: 1fr;
  }

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

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

  .brand h1 {
    font-size: 22px;
  }

  .market-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .board {
    gap: 4px;
  }

  .tile-label {
    min-width: 22px;
    height: 20px;
    padding: 0 4px;
    font-size: 11px;
  }

  .tile-shape {
    display: none;
  }

  .marker {
    width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .lobby-backdrop {
    align-items: start;
    padding: 12px;
  }

  .lobby {
    margin-top: max(12px, env(safe-area-inset-top));
    padding: 18px;
  }

  .lobby-brand {
    margin-bottom: 18px;
  }

  .center-stage {
    padding: 8px;
  }

  .board-wrap {
    padding: 5px;
  }

  .tide-card {
    padding: 7px;
  }

  .tide-card strong {
    font-size: 13px;
  }
}
