/* ===== Base & Reset ===== */
:root {
  --background: #000000;
  --foreground: #FFFFFF;
  --card: #ffffff;
  --card-foreground: #111827;
  --popover: #ffffff;
  --popover-foreground: #111827;
  --primary: #111827;
  --primary-foreground: #ffffff;
  --muted: #f3f4f6;
  --muted-foreground: #6b7280;
  --accent: #f9fafb;
  --accent-foreground: #111827;
  --border: #e5e7eb;
  --input: #e5e7eb;
  --ring: #9ca3af;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 0 solid transparent;
}

html, body, #root, .app-main {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  tab-size: 4;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  line-height: 1.5;
  background-color: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 100%;
  line-height: inherit;
  color: inherit;
  background-color: transparent;
  border-radius: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

button {
  cursor: pointer;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* ===== Layout ===== */
#root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.initial-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1rem;
}
#force-settings {
    padding: 0.5rem 1rem;
    border: 1px solid white;
    border-radius: 0.25rem;
}

.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.75rem 1.5rem;
  z-index: 50;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  flex-shrink: 0;
}

.app-main {
  flex: 1 1 0%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-top: 5.5rem;
}

#scoreboard {
  width: 100%;
  height: 100%;
  display: flex;
}

/* ===== Header UI ===== */
.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.question-counter {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}
.question-counter-label {
  font-size: 1.75rem;
  font-weight: 500;
  opacity: 0.6;
}
.question-counter-input {
  width: 5rem;
  background-color: transparent;
  border: none;
  text-align: left;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  padding: 0 4px;
  outline: none;
}

.icon-button {
  padding: 0.5rem;
  transition: all 150ms;
  color: rgba(255, 255, 255, 0.8);
}
.icon-button:disabled { 
  opacity: 0.2;
  cursor: not-allowed;
}
.icon-button:not(:disabled):hover {
  opacity: 1;
  transform: scale(1.1);
}
.icon-button svg {
  width: 1.5rem;
  height: 1.5rem;
}


/* ===== Player Card ===== */
.player-card-wrapper {
  flex: 1;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.5rem;
  min-width: 0;
}
.player-card-wrapper:last-child {
  border-right: none;
}
.player-card {
  --scale-factor: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  padding: 1rem 0.5rem;
  width: 100%;
  height: 100%;
  transition: all 300ms;
  position: relative;
}

.player-card.disabled {
  opacity: 0.4;
}
.player-card.disabled.is-winner {
  opacity: 1;
}

.status-badge {
  min-height: 32px;
}
.status-badge-content {
  padding: 0.375rem 1rem;
  border-radius: 0.5rem;
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-weight: 700;
}

.player-name-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  min-height: 25vh;
  flex-shrink: 0;
}

.player-nickname {
  font-size: calc(clamp(1rem, 3vh, 1.5rem) * var(--scale-factor));
  font-weight: 500;
  letter-spacing: 0.1em;
  writing-mode: vertical-rl;
  text-orientation: upright;
  color: var(--foreground);
  opacity: 0.8;
}

.player-name {
  font-size: calc(clamp(1.5rem, 5vh, 2.5rem) * var(--scale-factor));
  font-weight: 700;
  letter-spacing: 0.2em;
  writing-mode: vertical-rl;
  text-orientation: upright;
  color: var(--foreground);
}

.scores-container {
  width: 100%;
}

.score-display {
  text-align: center;
  margin-bottom: 1.5rem;
}
.scores-container .score-display:last-child {
  margin-bottom: 0;
}

.score-label {
  font-size: calc(clamp(0.8rem, 2vw, 1rem) * var(--scale-factor));
  opacity: 0.5;
}
.score-value {
  font-size: calc(clamp(3rem, 12vw, 8rem) * var(--scale-factor));
  line-height: 1;
  font-weight: 700;
}
.card-actions {
  width: 100%;
  padding: 0 0.5rem;
  margin-top: auto;
  opacity: 0.3;
  transition: opacity 200ms;
}
.player-card:hover .card-actions {
  opacity: 1;
}
.action-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.action-button {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  transition: all 150ms;
  border: 2px solid;
}
.action-button:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}
.action-button:not(:disabled):hover {
  transform: scale(1.05);
}
.action-button span {
  font-size: 1.5rem;
}

/* ===== Settings Dialog ===== */
dialog {
  width: 100%;
  max-width: 560px;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  padding: 0;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  background-color: var(--popover);
  color: var(--popover-foreground);
  margin: auto;
}
dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}
.dialog-wrapper {
  padding: 1.5rem;
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}
.dialog-close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.25rem;
  color: var(--muted-foreground);
}
.dialog-close-btn:hover {
  color: var(--popover-foreground);
}
.dialog-close-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}
.dialog-header {
  margin-bottom: 1.5rem;
}
.dialog-title {
  font-size: 1.25rem;
  font-weight: 700;
}
.tabs-list {
  display: flex;
  background-color: var(--muted);
  border-radius: 0.5rem;
  padding: 4px;
  margin-bottom: 1rem;
}
.tabs-trigger {
  flex: 1;
  padding: 0.5rem 0.25rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  transition: all 0.2s;
}
.tabs-trigger[data-state="active"] {
  background-color: var(--card);
  color: var(--card-foreground);
  box-shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);
}
.tabs-content[hidden] {
  display: none;
}
.form-group {
  margin-bottom: 1.25rem;
}
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}
.input-group {
  display: flex;
  gap: 0.5rem;
}
.input {
  display: flex;
  height: 2.5rem;
  width: 100%;
  border-radius: 0.375rem;
  border: 1px solid var(--input);
  background-color: var(--muted);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}
.input:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: var(--ring);
}
.input:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}
.input-group .button {
  flex-shrink: 0;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  height: 2.5rem;
  padding: 0 1rem;
  background-color: var(--primary);
  color: var(--primary-foreground);
}
.button.icon {
  width: 2.5rem;
  padding: 0;
}
.button.icon svg {
  width: 1rem;
  height: 1rem;
}
.player-list {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 8px;
}
.player-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
}
.player-list-item .form-group {
  margin-bottom: 0.75rem;
}
.player-list-item .form-group:last-child {
  margin-bottom: 0;
}
.player-list-item .input {
  height: 2.25rem;
}
.color-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.color-input-group .input[type="color"] {
  width: 2.25rem;
  height: 2.25rem;
  padding: 2px;
  flex-shrink: 0;
  border-radius: 0.375rem;
}
.delete-btn {
  color: var(--muted-foreground);
  margin-top: 0.5rem;
}
.delete-btn:hover {
  color: #ef4444;
}
.select-wrapper {
  position: relative;
}
.select-wrapper::after {
  content: '▼';
  font-size: 0.6rem;
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted-foreground);
}
select.input {
  padding-right: 2rem;
}
.rule-description {
  background-color: var(--muted);
  padding: 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}
.rule-description p {
  margin-bottom: 0.25rem;
}
.rule-description p:last-child {
  margin-bottom: 0;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.button.secondary {
  background-color: var(--accent);
  color: var(--accent-foreground);
  border: 1px solid var(--border);
}
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
.preset-btn {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  text-align: left;
}
.preset-btn:hover {
  background-color: var(--accent);
}
.preset-colors {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.5rem;
}
.color-swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 9999px;
  border: 1px solid rgba(0,0,0,0.1);
}
.export-section {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}
.export-section h3 {
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.export-section p {
  font-size: 0.875rem;
  color: var(--muted-foreground);
  margin-bottom: 1rem;
}
.export-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.export-info .button svg {
    width: 1rem;
    height: 1rem;
}
.grid {
    display: grid;
}
.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}
.gap-4 {
    gap: 1rem;
}
.game-list {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  max-height: 250px;
  overflow-y: auto;
}
.game-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.game-list-item:last-child {
  border-bottom: none;
}
.game-list-item.active {
  background-color: var(--accent);
}
.game-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.game-name {
  font-weight: 500;
}
.game-details {
  font-size: 0.875rem;
  color: var(--muted-foreground);
}
.game-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}
.button.small {
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.875rem;
}
.button.small.icon {
    width: 2rem;
    padding: 0;
}
.empty-list-message {
    padding: 1rem;
    text-align: center;
    color: var(--muted-foreground);
}