:root {
  font-family: Arial, Helvetica, sans-serif;
  color-scheme: dark;
  background: #111;
  color: #f3f3f3;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #111; }
button, select { font: inherit; }
button { cursor: pointer; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; gap: 18px; padding: 14px 18px;
  background: rgba(17,17,17,.95); border-bottom: 1px solid #333;
  backdrop-filter: blur(8px);
}
.topbar h1 { margin: 0; min-width: 0; font-size: clamp(1.1rem, 2vw, 1.6rem); }
.voting-timer { min-width: 220px; max-width: min(520px, 42vw); text-align: center; line-height: 1.25; }
.countdown-display { font-size: clamp(1.35rem, 2.25vw, 2rem); font-variant-numeric: tabular-nums; letter-spacing: .04em; white-space: nowrap; }
.voting-status { margin-top: 3px; font-size: clamp(.75rem, 1.1vw, .92rem); color: #c8c8c8; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.language-control { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.language-control select, .render-controls button, .icon-button, .confirm-dialog button {
  border: 1px solid #555; border-radius: 8px; background: #242424; color: #fff; padding: 9px 12px;
}
.discord-button, .submit-vote-button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 12px 22px; border: 1px solid #5865f2; border-radius: 8px;
  background: #5865f2; color: #fff; font-size: 1rem; font-weight: 700; line-height: 1;
  text-decoration: none; white-space: nowrap; box-shadow: 0 3px 12px rgba(0,0,0,.3);
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.discord-button:hover, .submit-vote-button:hover { background: #4752c4; border-color: #4752c4; }
.discord-button:active, .submit-vote-button:active { transform: translateY(1px); }
.discord-button:disabled, .submit-vote-button:disabled { opacity: .5; cursor: not-allowed; }
.logout-button { border: 1px solid #555; border-radius: 8px; background: #242424; color: #fff; padding: 9px 12px; }
main { padding: 18px; }
.tile-grid { display: grid; gap: 14px; grid-template-columns: repeat(5, minmax(0, 1fr)); max-width: 1600px; margin: 0 auto; }
.tile-card { min-width: 0; border: 1px solid #333; border-radius: 12px; overflow: hidden; background: #1b1b1b; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.tile-image-button { display: block; width: 100%; padding: 0; border: 0; background: #222; }
.tile-image-button img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.tile-info { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.tile-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-view-button {
  flex: 0 0 auto; align-self: stretch; margin: -10px -12px -10px auto; padding: 10px 12px 10px 14px;
  border: 0; border-left: 1px solid #4a4a4a; border-radius: 0; background: transparent; color: #fff;
}
.tile-view-button:hover { background: #242424; }
.modal[hidden] { display: none; }
.modal {
  --modal-padding: clamp(16px, 4vw, 64px); position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: var(--modal-padding); width: 100vw;
  height: var(--visual-viewport-height, 100dvh); max-height: var(--visual-viewport-height, 100dvh); overflow: hidden;
}
.modal-backdrop { position: absolute; inset: 0; border: 0; background: rgba(0,0,0,.82); padding: 0; }
.modal-panel {
  position: relative; z-index: 1; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1500px, 100%); height: min(900px, calc(var(--visual-viewport-height, 100dvh) - (2 * var(--modal-padding))));
  max-height: calc(var(--visual-viewport-height, 100dvh) - (2 * var(--modal-padding)));
  min-height: 0; border: 1px solid #444; border-radius: 14px; background: #151515;
  box-shadow: 0 20px 70px rgba(0,0,0,.6); overflow: hidden;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid #333; min-width: 0; }
.modal-header h2 { margin: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { width: 42px; height: 42px; font-size: 1.65rem; line-height: 1; flex: 0 0 auto; }
.render-stage { min-width: 0; min-height: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 12px; background: #0b0b0b; overflow: hidden; }
.render-stage img { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; object-position: center; }
.render-controls { display: flex; justify-content: center; align-items: center; gap: 14px; padding: 12px; border-top: 1px solid #333; min-height: 0; flex-wrap: wrap; }
.error-message { grid-column: 1 / -1; padding: 18px; border: 1px solid #7a3030; border-radius: 10px; background: #2a1414; }

.vote-modal { z-index: 120; }
.vote-panel {
  position: relative; z-index: 1; width: min(1100px, 100%);
  max-height: calc(var(--visual-viewport-height, 100dvh) - (2 * var(--modal-padding)));
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid #444; border-radius: 14px; background: #151515;
  box-shadow: 0 20px 70px rgba(0,0,0,.6); overflow: hidden;
}
.vote-panel form { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.vote-identity { margin-top: 3px; color: #bbb; font-size: .88rem; }
.vote-choices {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px;
  padding: 14px; overflow: auto; background: #0d0d0d;
}
.vote-choice {
  position: relative; display: block; overflow: hidden; border: 1px solid #333;
  border-radius: 10px; background: #1b1b1b; cursor: pointer;
}
.vote-choice input { position: absolute; opacity: 0; pointer-events: none; }
.vote-choice img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.vote-choice-label { display: block; padding: 9px 10px; text-align: center; border-top: 1px solid #333; }
.vote-choice:has(input:checked) { border-color: #5865f2; box-shadow: 0 0 0 2px #5865f2 inset; }
.vote-choice:has(input:checked) .vote-choice-label { background: #2a2f66; }
.vote-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 14px;
  padding: 12px 14px; border-top: 1px solid #333;
}
.vote-message { flex: 1; color: #ddd; }
.confirm-dialog {
  width: min(480px, calc(100vw - 30px)); border: 1px solid #444; border-radius: 14px;
  background: #151515; color: #fff; box-shadow: 0 20px 70px rgba(0,0,0,.6);
}
.confirm-dialog::backdrop { background: rgba(0,0,0,.82); }
.confirm-dialog h2 { margin-top: 0; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (orientation: portrait) {
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { grid-template-columns: 1fr; align-items: stretch; }
  .topbar h1 { text-align: center; }
  .voting-timer { width: 100%; max-width: none; min-width: 0; }
  .topbar-actions { width: 100%; justify-content: center; }
  .vote-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .topbar-actions { flex-wrap: wrap; }
  .language-control { flex: 1; justify-content: flex-end; }
  .discord-button { flex: 0 0 auto; min-width: 140px; }
  .modal { --modal-padding: 18px; }
}


.region-modal { z-index: 115; }
.region-panel {
  position: relative; z-index: 1; width: min(620px, 100%);
  border: 1px solid #444; border-radius: 14px; background: #151515;
  box-shadow: 0 20px 70px rgba(0,0,0,.6); overflow: hidden;
}
.region-choices {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px; padding: 18px; background: #0d0d0d;
}
.region-choice-button {
  min-height: 110px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid #444; border-radius: 12px; background: #1b1b1b; color: #fff;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.region-choice-button strong { font-size: 1.35rem; }
.region-choice-button span { color: #c8c8c8; font-size: .9rem; }
.region-choice-button:hover { background: #242424; border-color: #5865f2; }
.region-choice-button:active { transform: translateY(1px); }

@media (max-width: 560px) {
  .region-choices { grid-template-columns: 1fr; }
  .region-choice-button { min-height: 82px; }
}


.region-privacy-note {
  margin: 0;
  padding: 0 18px 18px;
  text-align: center;
  color: #9f9f9f;
  font-size: 0.82rem;
  line-height: 1.45;
  background: #0d0d0d;
}
.region-privacy-note a {
  color: #d7d7d7;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.region-privacy-note a:hover {
  color: #fff;
}

.confirm-vote-preview {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  margin: 16px 0;
}
.confirm-vote-preview img {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #343434;
  background: #0d0d0d;
}
.confirm-vote-preview p { margin: 0; }
@media (max-width: 520px) {
  .confirm-vote-preview { grid-template-columns: 82px minmax(0, 1fr); gap: 12px; }
  .confirm-vote-preview img { width: 82px; height: 82px; }
}

.vote-receipt {
  margin-top: 8px;
  color: #aaa;
  font-size: .88rem;
  line-height: 1.45;
}
