* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: #e5e5e5;
  color: #fff;
  font-family: Arial, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: calc(env(safe-area-inset-top) + 16px) env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + 16px) env(safe-area-inset-left);
}

.device {
  width: 340px;
  background: #111111;
  border: 3px solid #444444;
  border-radius: 20px;
  overflow: hidden;
  padding: 4px 0;
}

.device-title {
  text-align: center;
  color: #b3b3b3;
  font-size: 13px;
  letter-spacing: 1.5px;
  padding: 8px 0 4px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  color: #66AAFF;
}
.topbar .tisch { font-weight: bold; font-size: 14px; }
.topbar .icons { display: flex; gap: 6px; align-items: center; }
.topbar .icons svg { width: 14px; height: 14px; color: #66AAFF; }
.topbar .sum { font-size: 13px; }

.question {
  margin: 4px 6px;
  padding: 10px;
  background: #1A1A2E;
  border: 1px solid #334466;
  border-radius: 6px;
}
.q-label { color: #777777; font-size: 10px; }
.q-text { color: #ffffff; font-size: 16px; font-weight: bold; margin-top: 4px; }

.cardbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px;
}
.card-name {
  flex: 1;
  color: #66AAFF;
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-pos { color: #666666; font-size: 10px; }
.start-btn {
  background: #1A6A1A;
  color: #5DFF5D;
  border: 0;
  border-radius: 3px;
  padding: 3px 10px;
  font-size: 10px;
  font-family: inherit;
  cursor: pointer;
}
.start-btn:active { filter: brightness(0.85); }

.main-grid-wrap {
  display: grid;
  grid-template-columns: 1fr 18px;
  gap: 3px;
  padding: 3px;
}
.main-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  gap: 3px;
  aspect-ratio: calc(4 * 1.1) / 5;
}
.main-grid .cell {
  border-radius: 5px;
  background: #1A1A1A;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  aspect-ratio: 1.1 / 1;
}
.main-grid .cell.item {
  background: #E8931A;
  color: #3D2000;
  font-weight: bold;
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  white-space: pre-line;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
  border: 2px solid transparent;
}
.main-grid .cell.item:active { filter: brightness(0.9); }
.main-grid .cell.item.correct {
  background: #2D7A2D;
  color: #ffffff;
  border-color: #5DFF5D;
}
.main-grid .cell.item.wrong {
  background: #8A1A1A;
  color: #ffffff;
  border-color: #FF5555;
}

.scroll-col {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
}
.scroll-btn {
  background: #334466;
  color: #66AAFF;
  border: 1px solid #444444;
  border-radius: 3px;
  font-size: 11px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.scroll-btn:disabled {
  background: #1A1A1A;
  color: #555555;
  cursor: default;
}

.divider {
  height: 2px;
  margin: 3px 0;
  background: #333333;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 1px 3px;
}
.toolbar .tool {
  background: #222222;
  border: 1px solid #444444;
  border-radius: 4px;
  color: #66AAFF;
  font-size: 9px;
  font-family: inherit;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 3px;
}
.cat-grid .cat {
  background: #1A6AAA;
  color: #C8E6FF;
  border: 2px solid transparent;
  border-radius: 5px;
  font-size: 9px;
  font-weight: bold;
  font-family: inherit;
  line-height: 1.2;
  text-align: center;
  white-space: pre-line;
  aspect-ratio: 1.3 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  cursor: pointer;
}
.cat-grid .cat[data-card=""] { cursor: default; }
.cat-grid .cat.active {
  background: #2D7A2D;
  color: #ffffff;
  border-color: #5DFF5D;
}
.cat-grid .cat:not([data-card=""]):active { filter: brightness(0.9); }

.feedback {
  background: #1A1A1A;
  padding: 6px 8px;
  font-size: 11px;
  text-align: center;
  color: #AAAAAA;
}
.feedback.ok { color: #5DFF5D; }
.feedback.no { color: #FF5555; }

.score {
  background: #1A1A1A;
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}
.score .lbl { color: #888888; }
.score .ok { color: #5DFF5D; font-weight: bold; }
.score .no { color: #FF5555; font-weight: bold; }
.score .total { color: #66AAFF; font-weight: bold; }

.bottombar {
  display: flex;
  gap: 4px;
  padding: 6px;
}
.bot-btn, .bot-wide {
  background: #1A5580;
  color: #66AAFF;
  border: 0;
  border-radius: 4px;
  height: 30px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.bot-btn { width: 36px; }
.bot-wide { flex: 1; font-size: 10px; }
.bot-btn.ok { background: #1A6A1A; color: #5DFF5D; }

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.dialog-backdrop[hidden] { display: none; }
.dialog {
  width: 280px;
  background: #DCE8F5;
  border-radius: 6px;
  overflow: hidden;
  color: #111;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}
.dialog-header {
  background: #1A3A5A;
  color: #fff;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
  font-size: 12px;
}
.dialog-header button {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.dialog-body {
  overflow-y: auto;
  max-height: 300px;
  -webkit-overflow-scrolling: touch;
}
.dialog-body .info-row {
  display: grid;
  grid-template-columns: 24px 10px 1fr;
  padding: 6px 8px;
  border-bottom: 1px solid #AABBCC;
  font-size: 12px;
}
.dialog-body .info-row .num { text-align: right; color: #555; font-size: 11px; }
.dialog-ok {
  background: #1A3A5A;
  color: #fff;
  border: 0;
  padding: 10px;
  font-weight: bold;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
