/* Perry Acres -- the farm town.
 *
 * arcade.css already does the frame: the bars, the buttons, the dialogs, the
 * stage and full screen. This is only what a town needs on top: the money in
 * the bar, the Build menu, the panel that opens over the map, the notes, and
 * the camera buttons.
 *
 * The canvas fills whatever the stage is given. A camera does not letterbox:
 * a wider window shows more of the town, not the same town stretched.
 */

.town-page {
  --tw-panel-bg: var(--raised, var(--surface));
  --tw-good: #2f8f46;
  --tw-warn: #b7791f;
  --tw-bad: #c0392b;
}


/* ------------------------------------------------------------ the bar */

.tw-bar {
  gap: 8px 10px;
}

.tw-readout {
  align-items: center;
}

.tw-alert {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--tw-bad);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
}

.tw-bar button.is-on,
.tw-build-btn.is-on {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  font-weight: 600;
}

.tw-bar button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}


/* The Effects menu opens UNDER its button, not in the middle of the screen
   where the arcade menus open: the middle of the screen is the map, and the
   map is what an effect is shown on. main.js sets top and left when it opens. */
.tw-effects {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 11rem;
}

/* Its items are switches, so they show whether they are on. */
.tw-effects button[aria-pressed="true"] {
  background: var(--accent-soft);
  font-weight: 600;
}

.tw-effects button[aria-pressed="true"]::before {
  content: "\2713\00a0\00a0";
}


/* ------------------------------------------------------------ the Build menu */

.tw-build {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 9px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: var(--tw-panel-bg);
}

.tw-build[hidden] {
  display: none;
}

.tw-build__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tw-tab {
  min-height: 2.3rem;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.tw-tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.tw-build__cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
  gap: 8px;
}

.tw-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 9px 11px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.tw-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tw-card b {
  font-size: 1.02rem;
}

.tw-card__cost {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.tw-card__who {
  font-size: 0.82rem;
  color: var(--ink-faint);
}

/* Too dear right now: still there, still readable, plainly not affordable. */
.tw-card.is-dear {
  opacity: 0.55;
}

.tw-card.is-picked {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}


/* ------------------------------------------------------------ the stage */

.tw-stage {
  /* The town is the page. Taller than the arcade floor, because a map with
     a panel open over one side of it needs the room. */
  min-height: 26rem;
  background: #cfe0b8;
}

.tw-stage canvas {
  cursor: grab;
}

.tw-stage canvas:active {
  cursor: grabbing;
}

.tw-stage canvas[data-tool="build"],
.tw-stage canvas[data-tool="road"],
.tw-stage canvas[data-tool="remove"] {
  cursor: crosshair;
}

.tw-hint {
  margin: 0;
  padding: 0 4px;
  min-height: 1.4em;
  font-size: 0.95rem;
  color: var(--ink-muted);
}


/* ------------------------------------------------------------ notes over the map */

.tw-notes {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: min(34rem, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 3;
}

.tw-note {
  margin: 0;
  padding: 7px 14px;
  border-radius: 10px;
  background: rgba(20, 28, 20, 0.82);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  animation: tw-note 6s ease forwards;
}

.tw-note--good { background: rgba(33, 102, 52, 0.9); }
.tw-note--warn { background: rgba(140, 92, 20, 0.92); }
.tw-note--bad { background: rgba(150, 40, 32, 0.92); }

@keyframes tw-note {
  0% { opacity: 0; transform: translateY(-6px); }
  6% { opacity: 1; transform: none; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tw-note { animation: none; }
}


/* ------------------------------------------------------------ the panel */

.tw-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  width: min(20rem, calc(100% - 20px));
  max-height: calc(100% - 20px);
  overflow: auto;
  padding: 10px 12px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: var(--tw-panel-bg);
  color: var(--ink);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.tw-panel[hidden] {
  display: none;
}

.tw-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tw-panel__head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.tw-panel__close {
  min-width: 2.2rem;
  min-height: 2.2rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 1.4rem;
  cursor: pointer;
}

.tw-panel__close:hover {
  background: var(--accent-soft);
}

.tw-panel__state {
  margin: 4px 0 0;
  font-weight: 600;
  color: var(--tw-warn);
}

.tw-panel__rows {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 10px 0 0;
}

.tw-panel__rows dt {
  color: var(--ink-muted);
}

.tw-panel__rows dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.tw-panel__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.tw-panel__buttons button {
  min-height: 2.4rem;
  padding: 0 11px;
  border: 1px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.tw-panel__buttons button:hover:not(:disabled) {
  background: var(--accent-soft);
}

.tw-panel__buttons button:disabled {
  opacity: 0.45;
  cursor: default;
}

.tw-panel__blurb {
  margin: 12px 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink-faint);
}


/* ------------------------------------------------------------ the camera buttons */

.tw-camera {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(2, 2.6rem);
  gap: 6px;
  z-index: 2;
}

.tw-camera button {
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--rule-strong);
  border-radius: 9px;
  background: var(--tw-panel-bg);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.tw-camera button:hover {
  background: var(--accent-soft);
}


/* ------------------------------------------------------------ no 3D */

.tw-nogl {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--surface);
}

.tw-nogl[hidden] {
  display: none;
}


/* ------------------------------------------------------------ the dialogs */

.tw-report {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.tw-report th,
.tw-report td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--rule);
  text-align: right;
}

.tw-report th:first-child {
  text-align: left;
}

.tw-maps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
}

.tw-maps label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.tw-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.tw-custom label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tw-custom input {
  width: 6.5rem;
  min-height: 2.3rem;
  padding: 0 8px;
  border: 1px solid var(--rule-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}


/* ------------------------------------------------------------ phones

   A phone gets a note instead of the town (main.js decides, once, and adds
   is-phone): too much going on for a screen that size. Everything else is
   taken away, not just covered, so nothing behind the note can be tapped. */

.tw-phone {
  padding: 28px 20px;
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
}

.tw-phone[hidden] {
  display: none;
}

.tw-phone h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
}

.tw-phone p {
  margin: 8px 0;
  line-height: 1.5;
}

.town-page.is-phone .tw-bar,
.town-page.is-phone .tw-readout,
.town-page.is-phone .tw-build,
.town-page.is-phone .tw-stage,
.town-page.is-phone .tw-hint {
  display: none;
}


/* ------------------------------------------------------------ small screens */

@media (max-width: 720px) {
  /* The panel becomes a sheet along the bottom of the map, so it does not
     cover the square it is describing on a narrow screen. */
  .tw-panel {
    top: auto;
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    max-height: 48%;
  }

  .tw-camera {
    top: 10px;
    bottom: auto;
  }

  .tw-build__cards {
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  }
}
