/* ============================================================
   Settebello Scopa Club — retro 90s desktop look
   ============================================================ */

:root {
  --face: #c0c0c0;
  --face-light: #dfdfdf;
  --hilite: #ffffff;
  --shadow: #808080;
  --dark: #000000;
  --title-a: #000080;
  --title-b: #1084d0;
  --title-inactive-a: #808080;
  --title-inactive-b: #b5b5b5;
  --felt: #0a7d3e;
  --ink: #000;
  --select: #000080;
  --card-w: 60px;
  --card-h: 100px;
  font-family: Tahoma, "MS Sans Serif", "Segoe UI", Geneva, Verdana, sans-serif;
  font-size: 13px;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--felt);
  overflow: hidden;
}

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

/* ---------- 3D bevels ---------- */
.raised, .btn, .tb-btn, .window, .dropdown {
  border: 2px solid;
  border-color: var(--hilite) var(--dark) var(--dark) var(--hilite);
  box-shadow: inset -1px -1px var(--shadow), inset 1px 1px var(--face-light);
}
.inset, input[type="text"], input[type="email"], select, textarea, .inset-panel {
  border: 2px solid;
  border-color: var(--shadow) var(--hilite) var(--hilite) var(--shadow);
  box-shadow: inset 1px 1px var(--dark), inset -1px -1px var(--face-light);
}

/* ---------- App frame ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--face);
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 3px 3px 5px;
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff;
  user-select: none;
  flex: none;
}
.titlebar-icon {
  width: 16px; height: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='2.5' y='0.5' width='11' height='15' rx='1.5' fill='%23fffdf6' stroke='%23000'/%3E%3Ccircle cx='8' cy='8' r='3.6' fill='%23d9a41c' stroke='%237a5300' stroke-width='.8'/%3E%3Ccircle cx='8' cy='8' r='1.2' fill='%23b3261e'/%3E%3C/svg%3E") center/contain no-repeat;
  flex: none;
}
.titlebar-text {
  margin: 0;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.2px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.titlebar-buttons { display: flex; gap: 2px; }
.titlebar-buttons .tb-btn[data-action="close"] { margin-left: 2px; }

.tb-btn {
  width: 18px; height: 16px;
  padding: 0;
  background: var(--face);
  color: #000;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-width: 1px;
  box-shadow: inset -1px -1px var(--shadow), inset 1px 1px var(--face-light);
}
.tb-btn:active { border-color: var(--dark) var(--hilite) var(--hilite) var(--dark); box-shadow: inset 1px 1px var(--shadow); }
.glyph-min { width: 6px; height: 2px; background: #000; margin-top: 6px; }
.glyph-max { width: 9px; height: 8px; border: 1px solid #000; border-top-width: 2px; }
.glyph-close { font-weight: bold; font-size: 14px; line-height: 1; margin-top: -1px; }

/* ---------- Menu bar ---------- */
.menubar {
  flex: none;
  background: var(--face);
  border-bottom: 1px solid var(--shadow);
  box-shadow: 0 1px var(--hilite);
  position: relative;
  z-index: 50;
}
.menubar > ul {
  list-style: none;
  margin: 0;
  padding: 1px 2px;
  display: flex;
  flex-wrap: wrap;
}
.menu { position: relative; }
.menu-title {
  background: none;
  border: 1px solid transparent;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
}
.menu-title:hover, .menu-title:focus-visible, .menu.open > .menu-title {
  background: var(--select);
  color: #fff;
  outline: none;
}

.dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 190px;
  background: var(--face);
  list-style: none;
  margin: 0;
  padding: 2px;
  z-index: 60;
}
.menu.open > .dropdown { display: block; }
.dropdown button {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 4px 20px 4px 22px;
  cursor: pointer;
  white-space: nowrap;
}
.dropdown button:hover, .dropdown button:focus-visible { background: var(--select); color: #fff; outline: none; }
.dropdown .sep { height: 0; border-top: 1px solid var(--shadow); border-bottom: 1px solid var(--hilite); margin: 3px 1px; }
.shortcut { opacity: 0.85; }

/* ---------- Desktop ---------- */
.desktop {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--felt);
}
#cascade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Status bar ---------- */
.statusbar {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--face);
  border-top: 1px solid var(--hilite);
}
.status-cell {
  padding: 2px 6px;
  border: 1px solid;
  border-color: var(--shadow) var(--hilite) var(--hilite) var(--shadow);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.status-cell.grow { flex: 1; }

/* ---------- Windows ---------- */
.window {
  position: absolute;
  background: var(--face);
  padding: 2px;
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  z-index: 10;
}
.window[hidden] { display: none; }
.window.wide { width: min(700px, calc(100% - 32px)); }
.window.msgbox { width: min(360px, calc(100% - 32px)); }

.window-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 2px 4px;
  background: linear-gradient(90deg, var(--title-inactive-a), var(--title-inactive-b));
  color: var(--face-light);
  font-weight: bold;
  cursor: move;
  user-select: none;
  touch-action: none;
  flex: none;
}
.window.active .window-titlebar {
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff;
}
.window-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.window-body {
  padding: 10px 12px 12px;
  overflow: auto;
  min-height: 0;
}
.window-body > p:first-child { margin-top: 2px; }

.window-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.window-actions.center { justify-content: center; }

.btn {
  min-width: 80px;
  padding: 4px 12px;
  background: var(--face);
  cursor: pointer;
}
.btn:active { border-color: var(--dark) var(--hilite) var(--hilite) var(--dark); box-shadow: inset 1px 1px var(--shadow); }
.btn:focus-visible { outline: 1px dotted #000; outline-offset: -5px; }
.btn.default { outline: 1px solid #000; }

/* window menubar (inside the game window) */
.window-menubar {
  display: flex;
  gap: 2px;
  padding: 1px 2px;
  border-bottom: 1px solid var(--shadow);
  box-shadow: 0 1px var(--hilite);
  flex: none;
}
.wm-item {
  background: none;
  border: none;
  padding: 2px 8px;
  cursor: pointer;
}
.wm-item:hover { background: var(--select); color: #fff; }
.wm-check { display: inline-flex; align-items: center; gap: 4px; }
.wm-check input { margin: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; padding-left: 4px; position: relative; z-index: 1; }
.tab {
  background: var(--face);
  border: 2px solid;
  border-color: var(--hilite) var(--dark) transparent var(--hilite);
  border-radius: 3px 3px 0 0;
  padding: 3px 12px;
  margin-right: -2px;
  margin-top: 3px;
  cursor: pointer;
}
.tab.active { margin-top: 0; padding-bottom: 6px; margin-bottom: -2px; position: relative; z-index: 2; }

.inset-panel {
  background: #fff;
  padding: 4px 14px 12px;
  overflow: auto;
  max-height: min(60vh, 520px);
}
.window.wide .inset-panel { max-height: min(58vh, 560px); }

/* ---------- Prose ---------- */
.prose { line-height: 1.5; }
.prose h2 { font-size: 15px; margin: 14px 0 4px; color: var(--title-a); }
.prose h3 { font-size: 13px; margin: 12px 0 2px; }
.prose p { margin: 6px 0; }
.prose ul, .prose ol { margin: 6px 0; padding-left: 22px; }
.prose li { margin: 3px 0; }
.placeholder { background: #ffffcc; border: 1px dashed #b0a000; padding: 4px 8px; }
.small { font-size: 12px; margin-bottom: 0; }

/* list view (upcoming dates) */
.listview { background: #fff; overflow: auto; max-height: 50vh; }
.listview table { width: 100%; border-collapse: collapse; }
.listview th {
  position: sticky; top: 0;
  background: var(--face);
  text-align: left;
  font-weight: normal;
  padding: 3px 8px;
  border: 1px solid;
  border-color: var(--hilite) var(--shadow) var(--shadow) var(--hilite);
  white-space: nowrap;
}
.listview td { padding: 4px 8px; vertical-align: top; }
.listview tbody tr:hover td { background: var(--select); color: #fff; }
.listview tr.past td { color: var(--shadow); }
.listview td:first-child { white-space: nowrap; }

.score-table { border-collapse: collapse; margin: 6px 0; width: 100%; }
.score-table td, .score-table th { border: 1px solid var(--shadow); padding: 3px 8px; text-align: left; }
.score-table.compact td, .score-table.compact th { text-align: center; padding: 3px 4px; }
.score-table th { background: var(--face-light); }

.card-values {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 8px;
  margin: 8px 0;
}
.card-values figure { margin: 0; text-align: center; font-size: 11px; }
.card-values canvas { width: 48px; height: 80px; display: block; margin: 0 auto 2px; }

/* ---------- Forms ---------- */
.form fieldset { border: 1px solid var(--shadow); box-shadow: 1px 1px var(--hilite); padding: 8px 12px 12px; margin: 0; }
.form label { display: grid; gap: 3px; margin-top: 8px; }
.form input, .form select, .form textarea { background: #fff; padding: 3px 4px; width: 100%; }
.form textarea { resize: vertical; }

/* ---------- Message box ---------- */
.msg-row { display: flex; gap: 12px; align-items: flex-start; }
.msg-row p { margin: 6px 0 0; }
.msg-icon {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #000080;
  color: #000080;
  font: bold 20px Georgia, serif;
  display: grid;
  place-items: center;
}

/* ============================================================
   Scopa game window
   ============================================================ */
.window.game-window { width: min(780px, calc(100% - 32px)); }
.game {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--felt);
  background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.07), rgba(0,0,0,0.2));
  border: 2px solid;
  border-color: var(--shadow) var(--hilite) var(--hilite) var(--shadow);
  margin: 2px;
  overflow: auto;
  min-height: 0;
  color: #fff;
}
.game-row { display: flex; align-items: center; gap: 12px; }
.player-tag {
  width: 92px;
  flex: none;
  font-weight: bold;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
}
.pile-count { display: block; font-weight: normal; font-size: 11px; opacity: 0.9; }

.hand { display: flex; gap: 8px; min-height: var(--card-h); flex: 1; }
.table-felt {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 8px;
  min-height: calc(var(--card-h) * 2 + 24px);
  padding: 10px;
  border: 1px dashed rgba(255,255,255,0.25);
  border-radius: 10px;
}
.table-felt.empty::before {
  content: "Table is empty";
  color: rgba(255,255,255,0.45);
  font-style: italic;
  align-self: center;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  flex: none;
  border: 0;
  padding: 0;
  background: none;
  border-radius: 5px;
  box-shadow: 1px 2px 3px rgba(0,0,0,0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.3s ease;
  position: relative;
}
.card canvas { width: 100%; height: 100%; display: block; border-radius: 5px; pointer-events: none; }
button.card { cursor: pointer; }
button.card:hover:not(:disabled), button.card:focus-visible { transform: translateY(-8px); box-shadow: 2px 8px 10px rgba(0,0,0,0.5); outline: none; }
button.card:focus-visible { outline: 2px dotted #fff; outline-offset: 2px; }
button.card:disabled { cursor: default; }
.you-hand.waiting button.card { filter: brightness(0.85); }

.card.target { outline: 3px solid #ffe14d; outline-offset: 1px; }
.card.taking { outline: 3px solid #ffe14d; outline-offset: 1px; transform: scale(1.06); }
.card.played { outline: 3px solid #ffffff; outline-offset: 1px; transform: translateY(-4px); }
.card.gone { opacity: 0; transform: scale(0.8); }

.game-banner {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-6deg);
  font: bold 56px Georgia, "Times New Roman", serif;
  color: #ffe14d;
  text-shadow: 3px 3px 0 #7d1420, 6px 6px 0 rgba(0,0,0,0.35);
  pointer-events: none;
  animation: pop 1.1s ease both;
  z-index: 5;
}
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(0.3); }
  25% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1.15); }
  75% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
}

.game-dialog {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.35);
  z-index: 6;
  color: #000;
  padding: 10px;
}
.game-dialog[hidden] { display: none; }
.game-dialog .window { position: static; width: min(440px, 100%); max-height: 100%; }
.game-dialog .window-body { overflow: auto; }
.choice-list { display: grid; gap: 6px; margin-top: 8px; }
.choice {
  display: flex; align-items: center; gap: 6px;
  padding: 6px;
  background: var(--face);
  cursor: pointer;
  text-align: left;
}
.choice canvas { width: 33px; height: 55px; border-radius: 3px; }
.choice span { margin-left: 6px; }
.round-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.round-table th, .round-table td { border: 1px solid var(--shadow); padding: 3px 8px; text-align: center; }
.round-table th:first-child, .round-table td:first-child { text-align: left; }
.round-table tr.total td { font-weight: bold; background: var(--face-light); }

.game-status { border-top: 0; }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
  :root { --card-w: 43px; --card-h: 72px; }
  .menu-title { padding: 3px 6px; }
  .window, .window.wide, .window.game-window {
    left: 8px !important;
    right: 8px;
    top: 8px !important;
    width: auto;
    max-height: calc(100% - 16px);
  }
  .window-titlebar { cursor: default; }
  .player-tag { width: 64px; font-size: 12px; }
  .hand { gap: 5px; }
  .table-felt { gap: 5px; padding: 6px; min-height: calc(var(--card-h) * 2 + 16px); }
  .game { padding: 6px; }
  .game-banner { font-size: 40px; }
  .game-status { flex-wrap: wrap; }
  .game-status .status-cell.grow { flex-basis: 100%; white-space: normal; }
  .listview td, .listview th { padding: 3px 5px; }
  #status-clock { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .game-banner { transition: none; animation-duration: 0.01s; }
}

/* ---------- History page ---------- */
.history .timeline { max-height: none; margin: 6px 0 4px; }
.history .timeline td:first-child { font-weight: bold; color: var(--title-a); }
.history .timeline tbody tr:hover td:first-child { color: #fff; }
.card-strip { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0; }
.card-strip figure { margin: 0; text-align: center; font-size: 11px; }
.card-strip canvas { width: 60px; height: 100px; display: block; margin: 0 auto 3px; border-radius: 4px; box-shadow: 1px 2px 3px rgba(0,0,0,0.3); }
.card-strip.float { float: right; margin: 4px 0 8px 16px; }
.history h2 { clear: both; }
@media (max-width: 700px) {
  .card-strip canvas { width: 48px; height: 80px; }
  .card-strip.float { float: none; margin: 8px 0; }
}

/* ---------- Shop ---------- */
.shop-panel { padding: 12px; }
.shop-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px;
}
.shop-item {
  display: flex; flex-direction: column;
  background: var(--face, #c0c0c0); padding: 10px;
  border: 2px solid; border-color: #fff #808080 #808080 #fff;
}
.shop-pics {
  display: flex; justify-content: center; gap: 6px;
  background: #0a7d3e; padding: 10px; margin-bottom: 8px;
  border: 2px solid; border-color: #808080 #fff #fff #808080;
}
.shop-pics canvas { width: 54px; height: 90px; border-radius: 4px; box-shadow: 1px 2px 3px rgba(0,0,0,0.35); }
.shop-item h3 { font-size: 13px; margin: 0 0 4px; }
.shop-item p { margin: 0 0 10px; line-height: 1.4; flex: 1; }
.shop-buy { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.shop-price { font-weight: bold; font-size: 14px; }
@media (max-width: 700px) {
  .shop-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .shop-item { padding: 6px; }
  .shop-pics canvas { width: 40px; height: 67px; }
}
@media (max-width: 400px) { .shop-grid { grid-template-columns: 1fr; } }

/* warning icon: yellow triangle with "!" */
.msg-icon.warn {
  border: none; border-radius: 0; background: none;
  width: 34px; height: 32px; position: relative; color: #000;
  font: bold 18px Arial, sans-serif; padding-top: 8px;
}
.msg-icon.warn::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: #000;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.msg-icon.warn::after {
  content: ''; position: absolute; inset: 3px 3px 2px; z-index: -1;
  background: #ffe800;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.msg-icon.warn { isolation: isolate; }
