@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/Inter-Regular.ttf') format('truetype');
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  src: url('../fonts/Inter-Medium.ttf') format('truetype');
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  src: url('../fonts/Inter-Bold.ttf') format('truetype');
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 800;
  src: url('../fonts/Inter-ExtraBold.ttf') format('truetype');
}

:root {
  --bg-color: #f1f5f9;
  --text-color: #1e293b;
  --card-bg: #ffffff;
  --shadow-color: rgba(0, 0, 0, 0.08);
  --font-main: 'Inter', sans-serif;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 24px;
  box-sizing: border-box;
}

.app-container {
  width: 100%;
  max-width: 900px;
}

.app-header {
  text-align: center;
  margin-bottom: 32px;
}

.app-title {
  font-size: 32px;
  font-weight: 800;
  margin: 0 0 4px;
}

.app-subtitle {
  font-size: 18px;
  color: #64748b;
  margin: 0;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.category-card {
  display: flex;
  align-items: center;
  padding: 24px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--grad-start), var(--grad-end));
  color: white;
  text-decoration: none;
  box-shadow: 0 10px 25px -5px var(--shadow-color), 0 4px 6px -2px var(--shadow-color);
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
  position: relative;
  overflow: hidden;
}

.category-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 30px -10px var(--shadow-color), 0 8px 10px -4px var(--shadow-color);
}

.card-icon {
  font-size: 36px;
  margin-right: 20px;
  background: rgba(255, 255, 255, 0.15);
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.read-header .progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.read-header .progress-text {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
}

.card-content {
  flex: 1;
}

.card-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}

.card-desc {
  font-size: 15px;
  opacity: 0.9;
  margin: 0;
}

.app-footer {
  margin-top: 40px;
  font-size: 12px;
  color: #94a3b8;
  text-align: center;
}

/* General Subpage Styles */
.subpage-nav {
  width: 100%;
  max-width: 900px;
  margin-bottom: 16px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--card-bg);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  color: #475569;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.07);
  transition: all 0.2s;
}

.back-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.screen-content {
  /* width: 100%; */
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  padding: 24px 32px;
}

.subpage-header {
  text-align: center;
  margin-bottom: 24px;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 20px;
}

.subpage-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 4px;
}

.subpage-subtitle {
  font-size: 16px;
  color: #64748b;
  margin: 0;
}

.content-panel {
  margin-bottom: 24px;
}

.panel-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 12px;
  color: #334155;
}

.action-btn {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:hover {
  background: #1d4ed8;
}

.hidden {
  display: none !important;
}

/* Play Screen Header */
.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: var(--card-bg);
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.play-nav-btn {
  background: none;
  border: none;
  color: #475569;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background-color 0.2s;
}
.play-nav-btn:hover {
  background-color: #f1f5f9;
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-grow: 1;
  justify-content: center;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background-color: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  width: 0%;
  background-color: #2563eb;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  min-width: 50px;
  text-align: left;
}

.play-header-placeholder {
  width: 75px; /* Same as back button */
}


/* Czytanie - List Screen */
.reading-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.list-item-btn {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  text-align: left;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  /* Fix for overflow issue */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-btn:hover {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
  transform: translateY(-2px);
}

.custom-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 12px;
  display: block;
  box-sizing: border-box;
}

.custom-textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* Czytanie - Reading Screen */
.read-screen-container {
  position: fixed;
  inset: 0;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.read-screen-container.hidden {
  display: none;
}

.read-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: white;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  position: relative;
  z-index: 2;
}

.read-progress-bar {
  height: 4px;
  background: #e2e8f0;
  width: 100%;
}

.read-progress-bar-inner {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.3s ease;
}

.read-nav-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.read-nav-btn:hover {
  background: #f8fafc;
  color: #2563eb;
}

.speed-toggle-btn {
  min-width: 80px;
  text-align: center;
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}

.read-title-text {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.read-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  /* Apply padding here */
  padding: 0 24px;
  /* Ensure flex behavior centers the text container */
  display: flex;
  align-items: center;
  justify-content: center;
}

.read-text {
  font-size: clamp(48px, 15vw, 72px);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  color: var(--text-color);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  /* Remove padding from the text itself */
  padding: 0;
  /* Ensure the text block does not overflow its container */
  max-width: 100%;
  word-break: break-word;
  position: absolute;
  top: 10px;

}

.next-line-btn {
  position: absolute;
  bottom: max(30px, calc(env(safe-area-inset-bottom) + 20px));
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #2563eb;
  color: white;
  border: none;
  box-shadow: 0 8px 25px rgba(37, 99, 235, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.next-line-btn svg {
  width: 30px;
  height: 30px;
}

.next-line-btn:hover {
  background: #1d4ed8;
}

.next-line-btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: #94a3b8;
  box-shadow: none;
}

/* Dyktando - Play Screen */
.play-screen-container {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.play-screen-container.hidden {
  display: none;
}

.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: white;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  gap: 16px;
  position: relative;
  z-index: 2;
}

.play-nav-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.play-nav-btn:hover {
  background: #f8fafc;
  color: #2563eb;
}

.play-title-text {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-progress {
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: 8px;
}

.play-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card-bg);
}

.play-scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dyk-text-display {
  padding: 24px;
  font-size: 28px;
  line-height: 2;
  color: var(--text-color);
}

/* Blanks styling */
.dyk-blank {
  display: inline;
  font-weight: 700;
  border-radius: 4px;
  padding: 2px 4px;
}
.dyk-blank--pending {
  color: #94a3b8;
  border-bottom: 2px dotted #cbd5e1;
}
.dyk-blank--active {
  color: #2563eb;
  background: #eff6ff;
  border-bottom: 2px solid #2563eb;
  animation: dyk-pulse 1.5s ease-in-out infinite;
}
.dyk-blank--ok {
  color: #16a34a;
  background-color: #f0fdf4;
}
.dyk-blank--err {
  color: #dc2626;
  background-color: #fef2f2;
}
.dyk-blank--err s {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.dyk-correction {
  color: #16a34a;
  font-size: 0.7em;
  font-weight: 700;
  margin-left: 3px;
  vertical-align: super;
}

@keyframes dyk-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Choices bar */
.choices-bar {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: white;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
}
.choices-bar.hidden {
  display: none;
}
.choice-btn {
  flex: 1;
  padding: 18px 8px;
  border-radius: 14px;
  border: 2px solid #93c5fd;
  background: #eff6ff;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  color: #2563eb;
  font-family: inherit;
  transition: all 0.15s;
}
.choice-btn:hover, .choice-btn:active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
  transform: translateY(-2px);
}

/* Summary view */
.summary-view {
  padding: 24px;
}
.summary-text-display {
  font-size: 24px;
  line-height: 2;
  margin-bottom: 24px;
}
.summary-score-text {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  color: var(--text-color);
  margin: 0 0 24px;
  padding: 16px;
  background: #f1f5f9;
  border-radius: 12px;
}
.summary-back-btn {
  display: block;
  width: 100%;
  text-align: center;
  margin-bottom: 24px;
}

/* Ustawienia */
.settings-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  color: #475569;
}

.settings-input {
  width: 80px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  font-size: 16px;
  text-align: center;
  font-weight: 600;
}
.settings-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.start-btn {
  width: 100%;
  margin-top: 16px;
}

/* Grid z wyborem tabliczki */
.table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 12px;
}

.table-btn {
  padding: 16px 8px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.table-btn:hover {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
  transform: translateY(-2px);
}

.table-btn.active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.table-btn.all {
  grid-column: 1 / -1;
  font-size: 16px;
}

/* Ekran gry (mnożenie, dzielenie) */
.play-header {
  gap: 16px;
  position: relative;
  z-index: 2;
}

.play-progress-bar {
  height: 4px;
  background: #e2e8f0;
  width: 100%;
}

.play-progress-bar-inner {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.3s ease;
}

.play-progress-text {
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  min-width: 50px;
  text-align: right;
}

.problem-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.problem-text {
  font-size: clamp(48px, 18vw, 90px);
  font-weight: 800;
  color: var(--text-color);
}

.feedback-text {
  font-size: 20px;
  font-weight: 600;
  height: 30px;
  margin-top: 12px;
  opacity: 0;
  transition: opacity 0.2s;
}
.feedback-text.correct {
  color: #16a34a;
}
.feedback-text.incorrect {
  color: #dc2626;
}

/* Klawiatura numeryczna */
.keypad-container {
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: white;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
}

.answer-display {
  min-height: 60px;
  font-size: 40px;
  font-weight: 700;
  text-align: center;
  padding: 8px;
  border-radius: 12px;
  background: #f1f5f9;
  margin-bottom: 16px;
  color: var(--text-color);
}

.keypad {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.key-row {
  display: flex;
  gap: 10px;
}

.key {
  flex: 1;
  height: 60px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 24px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
}
.key:active {
  background: #e2e8f0;
  transform: scale(0.95);
}

.key-special {
  font-size: 20px;
  background: #f8fafc;
}

.submit-btn {
  width: 100%;
  padding: 18px;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  font-size: 18px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}
.submit-btn:hover {
  background: #1d4ed8;
}

/* Podsumowanie */
.summary-back-btn.secondary {
  background: #64748b;
  margin-top: 12px;
}
.summary-back-btn.secondary:hover {
  background: #475569;
}

/* Testy - Konfiguracja */
.test-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.ops-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.op-btn {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.op-btn:hover {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}
.op-btn.active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
  font-weight: 600;
}

.modes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-radius: 12px;
  border: 2px dashed #cbd5e1;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}
.mode-btn.active {
  border-style: solid;
  border-color: #2563eb;
  background: #eff6ff;
  color: #2563eb;
}
.mode-icon {
  font-size: 28px;
}
.mode-label {
  font-size: 16px;
  font-weight: 600;
  margin-top: 8px;
}

.hint-text {
  font-size: 14px;
  color: #64748b;
  margin-top: 12px;
  text-align: center;
}

/* Ustawienia i Historia (details/summary) */
.settings-details {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}
.settings-summary {
  padding: 12px 16px;
  cursor: pointer;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.settings-summary:hover {
  background: #f1f5f9;
}
.settings-summary .panel-title {
  margin: 0;
}
.settings-summary::after {
  content: '▼';
  font-size: 12px;
  color: #94a3b8;
  transition: transform 0.2s;
}
.settings-details[open] > .settings-summary::after {
  transform: rotate(180deg);
}

.settings-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
}
.settings-input-row {
  width: 80px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  text-align: center;
}
.settings-label-row.checkbox {
  gap: 12px;
}
.settings-label-row.checkbox input {
  width: auto;
  height: 18px;
  width: 18px;
}

.settings-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  border-top: 1px solid #f1f5f9;
  padding-top: 16px;
}
.settings-actions .action-btn.secondary {
  background: #64748b;
}
.settings-actions .action-btn.secondary:hover {
  background: #475569;
}

/* Historia */
.history-list {
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}
.history-item {
  padding: 12px;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
}
.history-item-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
.history-score {
  font-size: 16px;
}
.history-ops {
  font-size: 14px;
  color: #475569;
}
.history-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #64748b;
  margin-top: 6px;
}
.history-empty {
  text-align: center;
  color: #94a3b8;
  padding: 16px;
}

/* Ekran gry */
.play-status {
  font-size: 16px;
  font-weight: 600;
  color: #475569;
}
.play-score {
  font-size: 20px;
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}
.timer-display {
  font-size: 18px;
  font-weight: 600;
  color: #ef4444;
  margin-bottom: 8px;
}

/* Klawiatura dla testów */
#negate, #dot {
  font-size: 20px;
}
#submit {
  flex: 2;
}

/* Podsumowanie - modal */
.summary-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.summary-overlay.hidden {
  display: none;
}
.summary-modal {
  background: white;
  padding: 32px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  max-width: 90%;
  width: 360px;
}
.summary-modal h2 {
  font-size: 24px;
  margin: 12px 0;
}
.summary-modal-text {
  font-size: 18px;
  color: #475569;
  margin-bottom: 24px;
}

@media (max-width: 640px) {
  body {
    padding: 16px;
  }

  .app-title {
    font-size: 28px;
  }

  .app-subtitle {
    font-size: 16px;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }

  .test-config-grid {
    grid-template-columns: 1fr;
  }
}
