html,
body {
  box-sizing: border-box;
  margin: 0;
  overflow-x: hidden;
}

:root {
  --accent: #2e7dff;
  --bg-color: #ededed;
  --text-color: #000;
  --input-bg: #fafafa;
  --input-text: #000;
  --input-border: #ccc;
  --button-bg: var(--accent);
  --button-text: #fff;
  --vh: 100vh;
}

body.dark {
  --bg-color: #222;
  --text-color: #eee;
  --input-bg: #333;
  --input-text: #eee;
  --input-border: #555;
  --button-bg: var(--accent);
  --button-text: #fff;
}

header.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 840px;
  max-width: 50vw;
  margin: auto;
  padding: 0.5rem 1rem;
  background: var(--bg-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

header.topbar h1 {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: 1.5rem;
}

header.topbar .left,
header.topbar .right {
  display: flex;
  gap: 0.5rem;
}

body {
  font-family: sans-serif;
  font-size: 18px;
  padding: 4rem 1rem 6rem;
  max-width: 800px;
  margin: auto;
  background: var(--bg-color);
  color: var(--text-color);
}
i.icon {
  display: inline-block;
  font-style: normal;
}
h1 i.icon {
  display: block;
  font-size: 3rem;
}
td {
  padding: 0 0.5rem;
}
label {
  display: block;
  margin-top: 1rem;
}
input,
textarea,
select {
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.2rem;
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--input-border);
  box-sizing: border-box;
}
.lang-select {
  width: auto;
  margin-top: 0;
}
button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.icon-btn {
  margin-top: 0;
  padding: 0.4rem;
  background: none;
  color: var(--text-color);
}
a.icon-btn,
a.icon-btn:visited {
  color: var(--text-color);
  text-decoration: none;
}
.icon-btn svg {
  width: 1.2rem;
  height: 1.2rem;
  display: block;
  stroke: var(--text-color);
}
.icon-btn:hover {
  color: var(--accent);
}
.icon-btn:hover svg {
  stroke: var(--accent);
}
#logoutLink {
  position: relative;
}
.session-bubble {
  position: absolute;
  top: 5px;
  right: 5px;
  transform: translate(50%, -50%);
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  min-width: 1rem;
  height: 1rem;
  font-size: 0.6rem;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#focusControls .icon-btn svg {
  width: 1.5rem;
  height: 1.5rem;
}
#focusControls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  background: var(--bg-color);
}
#formArea {
  margin-top: 2rem;
}

fieldset {
  border: 1px solid var(--input-border);
  padding: 1rem;
  margin-top: 1rem;
  width: 100%;
  box-sizing: border-box;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  background-image: linear-gradient(to right bottom, var(--input-bg), var(--bg-color));
}

.field-wrapper {
  margin-top: 0.5rem;
}

legend {
  font-weight: bold;
  padding: 0 0.5rem;
}

body.focus #formArea {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(var(--vh) - 10rem);
}
body.focus fieldset {
  min-width: 20rem;
}
body.focus {
  overflow: hidden;
}

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.5rem 1rem;
  background: var(--bg-color);
}
body.focus #controls {
  bottom: 6rem;
  left: 0;
  right: 0;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.info-icon {
  position: relative;
  cursor: help;
  margin-left: 0.25rem;
}
.info-icon svg {
  width: 1rem;
  height: 1rem;
}
.tooltip {
  display: none;
  position: absolute;
  top: 50%;
  left: calc(100% + 0.25rem);
  transform: translateY(-50%);
  width: 20rem;
  background: #333;
  color: #fff;
  padding: 0.5rem;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  max-width: 100vw;
  font-size: 0.8rem;
  z-index: 10;
}
.info-icon:hover .tooltip {
  display: block;
}
.info-icon:hover svg {
  stroke: var(--accent);
}
.tooltip-section:not(:last-child) {
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.tooltip-title {
  font-weight: bold;
  display: block;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.font-preview {
  margin-top: 0.5rem;
  font-size: 1.2rem;
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.slide-in-left {
  animation: slideInLeft 0.3s ease-out;
}

.slide-in-right {
  animation: slideInRight 0.3s ease-out;
}


.color-field {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.font-field {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.font-field select {
  height: 2rem;
  margin: 0;
}

.color-field input[type='color'] {
  width: 4rem;
  padding: 0;
  height: 2rem;
}

.color-field button {
  height: 2rem;
}

.picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.picker-wrapper button,
.picker-wrapper input[type='color'] {
  margin: 0;
}

.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.25rem;
  width: 100%;
  padding: 0.25rem;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
}

.tag-input input,
.tag-input textarea {
  border: none;
  background: transparent;
  color: var(--input-text);
  flex: 1;
  min-width: 4rem;
}

.tag-input input:focus,
.tag-input textarea:focus {
  outline: none;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tag {
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  font-size: 0.9rem;
  cursor: no-drop;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tag.color {
  width: 1rem;
  height: 1rem;
  padding: 0;
  border-radius: 50%;
}

footer {
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
}

#gamification {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  background: var(--bg-color);
}

#stepDisplay {
  display: none;
  white-space: nowrap;
  text-align: right;
}

#gamifyBar {
  flex: 1;
}


progress {
  accent-color: var(--accent);
  border-radius: 0;
}
progress[value]::-webkit-progress-bar {
  background-color: var(--input-bg);
  border-radius: 0;
}

progress[value]::-webkit-progress-value {
  border-radius: 0;
  background-color: var(--accent);
}

@media (max-width: 900px) {
  html, body {
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden;
  }

  header.topbar {
    min-width: 0;
    max-width: 100vw;
    width: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.5rem 0.5rem;
    box-sizing: border-box;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  header.topbar .left,
  header.topbar .right {
    flex: 0 0 auto;
    width: auto;
    gap: 0.5rem;
    display: flex;
    align-items: center;
  }

  header.topbar h1 {
    flex: 1 1 auto;
    margin: 0;
    font-size: 1.2rem;
    text-align: center;
    order: 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body {
    padding: 6rem 0.5rem 6rem;
    max-width: 100vw;
    overflow-x: hidden;
  }

  input,
  textarea,
  select {
    width: 90vw;
    max-width: 90vw;
    box-sizing: border-box;
  }
  .lang-select {
    width: auto;
  }
  
  #templateSelect {
    width: 100%;
    max-width: 100%;
  }

  #templateChooser {
    display: block;
  }

  #focusControls,
  #gamification,
  #controls {
    max-width: 100vw;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  #controls {
    justify-content: space-around;
  }

  #controls .icon-btn {
    padding: 0.8rem;
  }

  #controls .icon-btn svg {
    width: 2rem;
    height: 2rem;
  }
  #gamification {
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 11;
  }

  body.focus.template-loaded header.topbar {
    top: 0.5rem;
  }

  #gamifyBar {
    height: 0.5rem;
  }

  body.focus #stepDisplay {
    display: flex;
    position: fixed;
    top: 4rem;
    right: 0.5rem;
    background: var(--accent);
    border-radius: 100vw;
    aspect-ratio: 1;
    padding: 0.5rem;
    align-items: center;
    justify-content: center;
    margin: 0.25rem;
    color: var(--button-text);
    text-shadow: 1px 1px 6px black;
    z-index: 12;
  }
  .tooltip {
    width: auto;
    min-width: 100%;
  }
  .info-icon:hover .tooltip {
    display: none;
  }
}

#thankYou {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-color);
  color: var(--text-color);
  padding: 1rem 2rem;
  border-radius: 100vw;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  font-size: 1.5rem;
  z-index: 1000;
  aspect-ratio: 1/1;
}

#thankYou .flag,
#thankYou i {
  display: block;
  text-align: center;
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.info-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.info-overlay-content {
  background: #333;
  color: #fff;
  padding: 1rem;
  border-radius: 4px;
  max-width: 90vw;
  max-height: var(--vh);
  overflow: auto;
}

.codes-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.codes-frame {
  width: 90vw;
  height: auto;
  max-height: calc(var(--vh) * 0.9);
  max-width: 800px;
  border: none;
  background: var(--bg-color);
  color: var(--text-color);
}

.help-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.help-overlay-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(3px);
}

.help-content {
  background: var(--bg-color);
  color: var(--text-color);
  padding: 1rem;
  border-radius: 8px;
  min-width: 480px;
  max-width: 90vw;
  max-height: calc(var(--vh) * 0.9);
  overflow: auto;
  position: relative;
}

@media (max-width: 900px) {
  .help-content {
    min-width: initial;
    max-width: 95vw;
  }
}

.help-content h2 {
  margin-top: 0;
}

.help-content ul {
  padding-inline-start: 1rem;
}

.help-content svg {
  max-width: 16px;
  max-height: 16px;
  vertical-align: text-bottom;
}

.help-arrows {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10001;
}

.help-line {
  stroke: var(--button-text);
  stroke-width: 2;
  fill: none;
}

.help-tip {
  position: absolute;
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--button-text);
  z-index: 10001;
}

.help-tip.up,
.help-tip.down {
  flex-direction: column;
}

.help-tip.up {
  flex-direction: column-reverse;
}

.help-arrow svg {
  width: 2.5rem;
  height: 2.5rem;
  stroke: currentColor;
}

.help-tip.down .help-arrow {
  transform: rotate(-90deg);
  margin-top: 0.5rem;
}

.help-tip.up .help-arrow {
  transform: rotate(90deg);
  margin-bottom: 0.5rem;
}

.help-tip.left .help-arrow {
  transform: rotate(180deg);
  margin-right: 0.5rem;
}

.help-tip.right .help-arrow {
  margin-left: 0.5rem;
}

.help-text {
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: #fff;
  pointer-events: none;
  z-index: 10002;
}

.help-highlight {
  position: relative;
  z-index: 10002;
  color: var(--accent);
}
.help-highlight svg {
  stroke: var(--accent);
}

.overlay-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
}

.help-content .overlay-close {
  top: 0;
  right: 0;
}

.overlay-close svg {
  width: 1.5rem;
  height: 1.5rem;
  stroke: var(--text-color);
}

.overlay-close:hover svg {
  stroke: var(--accent);
}

body.embed input,
body.embed select,
body.embed button {
  width: auto;
}
body.embed {
  padding: 1rem;
  max-width: 100vw;
  width: 100vw;
  box-sizing: border-box;
  overflow: auto;
}

body.embed main {
  margin: 0 !important;
}

.coin {
  position: fixed;
  z-index: 1000;
  background: var(--button-bg);
  color: var(--text-color);
  border-radius: 50%;
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: transform 0.6s ease-out, opacity 0.6s ease-out;
}

.progress-pop {
  animation: progressPop 0.3s ease-out;
}

@keyframes progressPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

body.login {
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: var(--vh);
}

.login-container {
  text-align: center;
}

.login-container h1 {
  position: relative;
}

.expired-bubble {
  position: absolute;
  left: 50%;
  bottom: 100%;
  margin-bottom: 0.25rem;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: normal;
  min-width: 200px;
  box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.15);
}

.expired-bubble::after {
  content: '';
  position: absolute;
  left: 0.5rem;
  bottom: -18px;
  border-width: 10px;
  border-style: solid;
  border-color: var(--accent) transparent transparent transparent;
}

@media (max-width: 900px) {
  .expired-bubble {
    left: 0;
    min-width: initial;
    max-width: 95vw;
  }
  .expired-bubble::after {
    left: 50%;
  }
}

.login-form {
  display: flex;
  flex-direction: column;
  width: 20rem;
  max-width: 90vw;
}

.login-form input,
.login-form button {
  text-align: center;
  width: 100%;
}

.error {
  color: red;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.confirm-box {
  background: var(--bg-color);
  color: var(--text-color);
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  max-width: 90vw;
}

.confirm-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.confirm-buttons button {
  margin: 0;
}

#swipeHint {
  position: fixed;
  bottom: 40%;
  left: 50%;
  transform: translate(-50%, 0);
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
  animation: swipeHint 1s ease-out forwards;
}

@keyframes swipeHint {
  0% { opacity: 0; transform: translate(-50%, 0) translateX(-20px); }
  20% { opacity: 1; }
  80% { opacity: 1; transform: translate(-50%, 0) translateX(20px); }
  100% { opacity: 0; transform: translate(-50%, 0) translateX(40px); }
}

body.focus.template-loaded #templateChooser {
  display: none;
}

body.focus.template-loaded #formArea {
  margin-top: 0;
}

.codes-table-wrapper {
  overflow-x: auto;
}
.codes-table-wrapper table {
  min-width: 40rem;
}
@media (max-width: 600px) {
  .codes-table-wrapper table {
    font-size: 0.9rem;
  }
}