/* Main CSS for PyCombat PWA */

/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    background-color: #f5f5f5;
}

/* App layout */
#app {
    min-height: 100vh;
    /* iOS safe area support */
    min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    display: flex;
    flex-direction: column;
}

/* Update notification banner */
.update-notification {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 999;
    animation: slideDown 0.3s ease-out;
}

.update-notification.hidden {
    display: none;
}

.update-notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
    flex-wrap: wrap;
}

.update-notification-icon {
    font-size: 20px;
    animation: rotate 2s linear infinite;
}

.update-notification-text {
    flex: 1;
    min-width: 200px;
    font-size: 14px;
    font-weight: 500;
}

#update-version-info {
    font-size: 12px;
    opacity: 0.9;
    margin-left: 8px;
}

.update-notification-button {
    padding: 6px 16px;
    background-color: white;
    color: #667eea;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.update-notification-button:hover {
    background-color: #f0f0f0;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.update-notification-button:active {
    transform: translateY(0);
}

.update-notification-dismiss {
    padding: 4px 8px;
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
}

.update-notification-dismiss:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Responsive update notification */
@media (max-width: 600px) {
    .update-notification-content {
        gap: 8px;
    }

    .update-notification-text {
        flex: 1 1 100%;
        min-width: 100%;
        text-align: center;
    }

    .update-notification-button {
        flex: 1;
    }
}

.character-selector {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.character-selector select {
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: white;
}

.export-header-btn {
    padding: 4px 8px;
    font-size: 12px;
    white-space: nowrap;
}

.load-header-btn {
    padding: 4px 8px;
    font-size: 12px;
    white-space: nowrap;
    background-color: #007bff;
    color: white;
    border: 1px solid #007bff;
}

.manage-dropdown {
    position: relative;
    display: inline-block;
}

.manage-header-btn {
    padding: 4px 8px;
    font-size: 12px;
    white-space: nowrap;
    background-color: #6c757d;
    color: white;
    border: 1px solid #6c757d;
    cursor: pointer;
}

.manage-header-btn:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

.manage-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 180px;
}

.manage-menu.hidden {
    display: none;
}

.manage-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid #eee;
}

.manage-menu-item:last-child {
    border-bottom: none;
}

.manage-menu-item:hover {
    background-color: #f8f9fa;
}

.manage-menu-item[data-action="delete"] {
    color: #dc3545;
}

.manage-menu-item[data-action="delete"]:hover {
    background-color: #f8d7da;
}

/* Tab navigation */
.tab-nav {
    background-color: white;
    border-bottom: 1px solid #ccc;
    display: flex;
    padding: 0 16px;
    align-items: center;
}

.tab-button {
    padding: 12px 24px;
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    font-size: 14px;
    font-weight: 500;
}

.tab-button:hover {
    background-color: #f0f0f0;
}

.tab-button.active {
    border-bottom-color: #007acc;
    color: #007acc;
}

/* Panel container */
.panel-container {
    flex: 1;
    padding: 8px;
}

.panel {
    display: none;
    width: 100%;
}

.panel.active {
    display: block;
}

/* Common panel layouts */
.attack-panel,
.spells-panel,
.items-panel,
.worksheet-panel {
    display: flex;
    gap: 12px;
    align-items: start;
}

/* Panel column sizing */
.stats-column {
    flex: 0 0 auto;
    width: 320px;
    max-width: 320px;
}

.combat-results-column,
.spells-main-column {
    flex: 0 0 auto;
    width: 400px;
    max-width: 400px;
}

.environment-column {
    flex: 0 0 auto;
    width: 280px;
    max-width: 280px;
}

/* Character stats */
.character-stats {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px;
}

.character-header {
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eee;
}

.character-name {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 2px;
}

.character-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.character-info-row {
    display: flex;
    gap: 8px;
}

.class-select,
.race-select,
.level-input {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
}

.export-char-btn {
    padding: 4px 8px;
    font-size: 11px;
    white-space: nowrap;
}

.level-input {
    width: 60px;
}

.race-select {
    width: 90px;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-header {
    display: grid;
    grid-template-columns: 1fr 58px 48px;
    gap: 8px;
    align-items: center;
    padding-bottom: 4px;
    border-bottom: 1px solid #ddd;
    margin-bottom: 4px;
}

.column-header {
    font-size: 11px;
    font-weight: 600;
    color: #666;
    text-align: center;
}

.stat-row {
    display: grid;
    grid-template-columns: 1fr 58px 48px;
    gap: 8px;
    align-items: center;
}

.stat-row label {
    font-size: 12px;
    color: #666;
}

.base-value {
    width: 50px;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 2px;
    text-align: center;
    font-size: 12px;
}

.current-value {
    min-width: 40px;
    text-align: center;
    font-weight: 500;
    font-size: 14px;
}

.weight-select {
    width: 80px;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 2px;
    font-size: 12px;
}

.export-section {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
}

.export-section .control-button {
    width: 100%;
    padding: 8px;
    font-size: 12px;
    margin-bottom: 5px;
}

.export-section .control-button:last-child {
    margin-bottom: 0;
}

.reset-button {
    background-color: #dc3545 !important;
    color: white !important;
    border-color: #dc3545 !important;
}

.reset-button:hover {
    background-color: #c82333 !important;
    border-color: #bd2130 !important;
}

/* Combat results */
.combat-results {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 4px;
}

.combat-line {
    display: grid;
    grid-template-columns: 100px 80px 1fr;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
}

.combat-line:last-child {
    border-bottom: none;
}

.attack-type {
    font-weight: 500;
    color: #333;
}

.tohit-value,
.damage-value,
.value {
    font-family: 'Monaco', 'Menlo', monospace;
    font-weight: 600;
    color: #007acc;
}

.damage-value {
    color: #d73a49;
}

/* Environment controls */
.environment-controls {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
}

.environment-section,
.weapon-section,
.modifiers-section {
    margin-bottom: 10px;
}

.environment-section:last-child,
.weapon-section:last-child,
.modifiers-section:last-child {
    margin-bottom: 0;
}

.environment-controls h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #333;
}

.power-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.nullify-magic {
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.weapon-select {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
}

.modifier-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.modifier-row:last-child {
    margin-bottom: 0;
}

.modifier-input {
    width: 60px;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 2px;
    text-align: center;
    font-size: 12px;
}

/* Action buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    width: 140px;
}

.action-button {
    padding: 8px 16px;
    border: 1px solid #007acc;
    border-radius: 4px;
    background: #007acc;
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.action-button:hover {
    background: #005a9e;
}

.details-checkbox {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* Spells panel specific */
.spells-main-column {
    flex: 1;
    min-width: 0;
}

.spells-table-section {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 6px;
    margin-bottom: 6px;
    width: 100%;
}

.spells-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    table-layout: fixed;
}

.spells-table th {
    background: #f0f0f0;
    border: 1px solid #ccc;
    padding: 6px 4px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
}

.spells-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.spells-table th.sortable:hover {
    background: #e8e8e8;
}

.sort-indicator {
    font-weight: bold;
    color: #007acc;
}

.spells-table th:nth-child(1) { width: 50px; }  /* On */
.spells-table th:nth-child(2) { width: 180px; } /* Spell */
.spells-table th:nth-child(3) { width: 60px; }  /* Value */
.spells-table th:nth-child(4) { width: 60px; }  /* Level */
.spells-table th:nth-child(5) { width: 110px; } /* Power */
.spells-table th:nth-child(6) { width: 250px; } /* Description */

.spells-table td {
    border: 1px solid #ccc;
    padding: 4px;
    vertical-align: middle;
    font-size: 13px;
}

.spell-row.active {
    background: #f0f8ff;
}

.spell-row.inactive {
    background: #f9f9f9;
    opacity: 0.7;
}

.spell-checkbox {
    margin: 0;
    transform: scale(0.8);
}

.spell-name {
    font-weight: 500;
    color: #333;
}

.spell-value-input,
.spell-level-input {
    width: 50px;
    padding: 3px 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
    text-align: center;
}

.spell-description-input {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
    text-align: left;
    background-color: white;
}

.spell-power-select {
    width: 110px;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
}

.spell-description {
    font-style: italic;
    color: #666;
}

.spell-controls {
    display: flex;
    gap: 12px;
}

/* Add Spells Dialog */
.add-spells-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}

/* Spell form layout - scoped to dialog only */
.add-spells-dialog .spell-form {
    margin-bottom: 20px;
}

.add-spells-dialog .spell-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.add-spells-dialog .spell-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.add-spells-dialog .spell-field.full-width {
    flex: 1 1 100%;
}

.add-spells-dialog .spell-field label {
    font-weight: 500;
    font-size: 14px;
    color: #333;
}

.add-spells-dialog .spell-field input,
.add-spells-dialog .spell-field select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

.add-spells-dialog .spell-field input:focus,
.add-spells-dialog .spell-field select:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.dialog-content {
    background: white;
    border-radius: 8px;
    padding: 24px;
    min-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.dialog-content h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 600;
}

.spell-selection,
.spell-level-selection {
    margin-bottom: 16px;
}

.spell-selection label,
.spell-level-selection label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
}

.spell-selection select,
.spell-level-selection input {
    width: 100%;
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 12px;
}

.dialog-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.dialog-buttons button {
    padding: 8px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 14px;
}

.dialog-buttons button:first-child {
    background: #007acc;
    color: white;
    border-color: #007acc;
}

.dialog-buttons button:hover {
    opacity: 0.8;
}

.delete-spell-list {
    max-height: 300px;
    overflow-y: auto;
    margin: 16px 0;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 8px;
}

.delete-spell-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.delete-spell-item input[type="checkbox"] {
    margin: 0;
}

.delete-spell-item label {
    flex: 1;
    cursor: pointer;
    font-size: 14px;
    text-decoration: underline dotted #999;
    text-underline-offset: 2px;
}

.delete-spell-item label:hover {
    text-decoration: underline solid #333;
}

.delete-spell-list + .dialog-buttons button {
    min-width: 80px;
    padding: 8px 12px;
    font-size: 14px;
    background: #f8f9fa !important;
    border: 1px solid #6c757d !important;
    border-radius: 4px;
    color: #333 !important;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.delete-spell-list + .dialog-buttons button:hover {
    background: #e9ecef !important;
    color: #000 !important;
}

.control-button {
    padding: 6px 12px;
    border: 1px solid #007acc;
    border-radius: 3px;
    background: white;
    color: #007acc;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    flex: 1;
}

.control-button:hover {
    background: #007acc;
    color: white;
}

/* Items panel specific */
.items-list {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 16px;
}

.item-entry {
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.item-entry:last-child {
    border-bottom: none;
}

.item-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.item-effects {
    font-size: 12px;
    color: #666;
}

.equipment-section {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 16px;
}

.equipment-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.equipment-item {
    margin-bottom: 16px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 12px;
    background: #fafafa;
}

.equipment-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.equipment-row .equipment-select {
    flex: 1;
    min-width: 100px;
}

.equipment-row label:first-child {
    flex-shrink: 0;
}

.equipment-row:last-child {
    margin-bottom: 0;
}

.equipment-item:last-child {
    margin-bottom: 16px;
}

.equipment-select {
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
    min-width: 120px;
}

.plus-input {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
    text-align: center;
}

.metaphysical-checkbox {
    margin-right: 4px;
}

.carried-checkbox {
    margin-left: 4px;
}

.carried-label {
    margin-left: auto;
    display: flex;
    align-items: center;
}

.worn-checkbox {
    margin-left: 4px;
}

.worn-label {
    margin-right: 4px;
    font-size: 12px;
}

.item-controls {
    display: flex;
    align-items: center;
    margin-left: auto;
}

.item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.equipment-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.equipment-row.special-weapon {
    justify-content: space-between;
}

.equipment-row.special-weapon .equipment-select {
    max-width: 280px;
}

.equipment-row:not(.special-weapon) .equipment-select {
    flex: 1;
    max-width: 200px;
}

.training-section {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 16px;
}

.training-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #333;
}

.training-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.training-item:last-child {
    margin-bottom: 0;
}

.training-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.training-input {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
    text-align: center;
}

.absorption-value {
    font-family: 'Monaco', 'Menlo', monospace;
    font-weight: 600;
    color: #007acc;
    font-size: 12px;
}


/* Worksheet panel specific */
.worksheet-section {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 16px;
    height: calc(100vh - 220px);
    display: flex;
    flex-direction: column;
}

.worksheet-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.worksheet-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 16px;
}

.worksheet-tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
}

.worksheet-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-size: 13px;
}

.worksheet-tab:hover {
    background: #f0f0f0;
}

.worksheet-tab.active {
    border-bottom-color: #007acc;
    color: #007acc;
    font-weight: 500;
}

.worksheet-content {
    flex: 1;
    overflow-y: auto;
}

.worksheet-display {
    display: none;
}

.worksheet-display.active {
    display: block;
}

.worksheet-display h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

.worksheet-display pre {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    line-height: 1.4;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
    border-radius: 4px;
    padding: 12px;
    white-space: pre-wrap;
    overflow-x: auto;
}

/* Dialog styles */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.dialog {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    margin: 20px;
}

.dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dialog-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.close-button {
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-button:hover {
    color: #333;
}

.dialog-content {
    padding: 20px;
}

.dialog-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    text-align: right;
}

.dialog-button {
    padding: 8px 16px;
    border: 1px solid #007acc;
    border-radius: 4px;
    background: #007acc;
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

.dialog-button:hover {
    background: #005a9e;
}

/* Attack result dialog specific */
.attack-result-dialog .dialog-content {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 12px;
}

.result-section {
    margin-bottom: 16px;
}

.result-section:last-child {
    margin-bottom: 0;
}

.attack-breakdown,
.damage-result,
.bash-result,
.absorption-result {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 12px;
}

.roll-line {
    margin-bottom: 4px;
}

.roll-line:last-child {
    margin-bottom: 8px;
}

.damage-result,
.bash-result {
    margin-top: 12px;
    font-weight: 600;
    color: #d73a49;
}

/* Responsive design */
@media (max-width: 1200px) {
    .stats-column {
        width: 300px;
        max-width: 300px;
    }
    
    .combat-results-column,
    .spells-main-column {
        width: 360px;
        max-width: 360px;
    }
    
    .environment-column {
        width: 260px;
        max-width: 260px;
    }
}

/* iPad portrait and mobile */
@media (max-width: 1024px) {
    .attack-panel,
    .spells-panel,
    .items-panel,
    .worksheet-panel {
        flex-direction: column;
        gap: 16px;
        align-items: center;
    }
    
    .stats-column,
    .combat-results-column,
    .spells-main-column,
    .environment-column {
        width: 100%;
        max-width: 500px; /* Reasonable content width */
        flex: 0 0 auto;
    }
    
    .stats-column,
    .environment-column {
        order: -1;
    }
}

/* Phone screens */
@media (max-width: 600px) {
    .stats-column,
    .combat-results-column,
    .spells-main-column,
    .environment-column {
        max-width: 100%;
    }
    
    /* Hide statistics and environment sections in worksheet panel on mobile */
    .worksheet-panel .stats-column,
    .worksheet-panel .environment-column {
        display: none !important;
    }
    
    /* Make worksheet section take full available space */
    .worksheet-panel .worksheet-section {
        height: calc(100vh - 120px) !important;
        max-height: none !important;
        flex: 1 !important;
    }
    
    /* Ensure worksheet panel is in column layout on mobile */
    .worksheet-panel {
        flex-direction: column !important;
    }
    
    
    .panel-container {
        padding: 8px;
    }
    
    /* Larger touch targets for phones */
    .action-button {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 48px;
    }
    
    .tab-button {
        padding: 16px 20px;
        font-size: 16px;
        min-height: 48px;
    }
    
    /* Better input sizing for phones */
    .base-value, .modifier-input, .training-input, .plus-input {
        min-height: 44px;
        font-size: 16px;
        padding: 8px;
    }
    
    /* Improve select dropdowns on phones */
    select {
        min-height: 44px;
        font-size: 16px;
        padding: 8px;
    }
    
    /* Optimize tables for phone screens */
    .spells-table {
        font-size: 12px;
    }
    
    .spells-table th,
    .spells-table td {
        padding: 6px 4px;
    }
    
    /* Stack combat result lines vertically on very small screens */
    .combat-line {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 4px;
    }
    
    .attack-type {
        font-weight: 600;
        border-bottom: 1px solid #eee;
        padding-bottom: 4px;
    }
}

/* Combat Results Section */
.results-content {
    display: flex;
    gap: 12px;
    margin-top: 2px;
    margin-bottom: 0px;
}

.results-section {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    flex-grow: 1;
}

.results-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #333;
}

.results-display {
    height: 200px;
    overflow-y: auto;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    background: #f8f9fa;
    padding: 8px;
    margin-bottom: 12px;
    flex-grow: 1;
}

.result-entry {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #dee2e6;
}

.result-entry:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

.result-entry pre {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    line-height: 1.4;
    margin: 0;
    white-space: pre-wrap;
    color: #495057;
}

.results-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.control-button {
    padding: 6px 12px;
    border: 1px solid #6c757d;
    border-radius: 4px;
    background: #6c757d;
    color: white;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.control-button:hover {
    background: #5a6268;
    border-color: #5a6268;
}

/* iOS/iPad specific optimizations */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: transparent;
        /* Prevent bounce scrolling on iPhone */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: none;
    }
    
    /* Allow text selection in input fields and content areas */
    input, textarea, .result-entry, .worksheet-display {
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* Improve touch targets for iOS */
    button, select, .tab-button {
        min-height: 44px;
        -webkit-appearance: none;
        border-radius: 8px;
    }
    
    /* Ensure checkboxes remain visible and touchable on iOS */
    input[type="checkbox"] {
        min-height: 20px;
        min-width: 20px;
        -webkit-appearance: checkbox; /* Keep native checkbox appearance */
        transform: scale(1.2); /* Make them slightly larger for easier touch */
    }
    
    /* Prevent zoom on input focus */
    input, select, textarea {
        font-size: 16px;
    }
    
    /* iPhone specific optimizations */
    @media (max-width: 480px) {
        /* Better button spacing for iPhone */
        .results-content {
            flex-direction: column;
        }
        
        .action-buttons {
            flex-direction: row;
            flex-wrap: wrap;
            justify-content: center;
            width: auto;
        }
        
        .action-button {
            margin: 4px;
            flex: 1 1 calc(50% - 8px);
            min-width: 120px;
        }
        
        
        /* Stack modifier rows on iPhone */
        .modifier-row {
            flex-direction: column;
            align-items: stretch;
            gap: 8px;
        }
        
        .modifier-row label {
            text-align: center;
            font-weight: 600;
        }
    }
}

/* Android specific optimizations */
@supports not (-webkit-touch-callout: none) {
    /* Android Chrome/Firefox specific styles */
    
    /* Improve touch feedback on Android */
    button:active, .tab-button:active {
        background-color: rgba(0, 122, 204, 0.1);
        transform: scale(0.98);
    }
    
    /* Android Chrome address bar handling */
    .panel-container {
        min-height: calc(100vh - 120px); /* Account for Android Chrome UI */
    }
    
    /* Better scroll behavior on Android */
    .results-display, .worksheet-content {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Android specific touch targets */
    @media (max-width: 480px) {
        /* Optimize for Android gesture navigation */
        .results-content {
            flex-direction: column;
        }
        
        .action-buttons {
            flex-direction: row;
            flex-wrap: wrap;
            justify-content: center;
        }
        
        /* Mobile worksheet adjustments for better text wrapping */
        .worksheet-display pre {
            font-size: 9px;
            padding: 6px;
            margin: 0;
            max-width: 100%;
            box-sizing: border-box;
            word-break: break-all;
            overflow-wrap: break-word;
            white-space: pre-wrap;
            width: 100%;
        }
        
        .worksheet-section {
            padding: 8px;
            height: calc(100vh - 160px);
            width: 100%;
            margin: 0;
            padding-bottom: 16px; /* Extra space for gesture bar */
        }
        
        .worksheet-content {
            width: 100%;
            overflow-x: hidden;
        }
        
        .worksheet-panel {
            padding: 0 8px;
        }
    }
    
    /* Landscape mode optimizations */
    @media (max-width: 1024px) and (orientation: landscape) {
        .worksheet-section {
            height: calc(100vh - 120px); /* Larger height in landscape */
        }
        
        .worksheet-display pre {
            font-size: 11px; /* Slightly larger font in landscape */
        }
        
        /* Hide statistics and environment sections in worksheet panel on mobile landscape */
        .worksheet-panel .stats-column,
        .worksheet-panel .environment-column {
            display: none !important;
        }
        
        /* Make worksheet section take full available space in landscape */
        .worksheet-panel .worksheet-section {
            height: calc(100vh - 100px) !important;
            max-height: none !important;
            flex: 1 !important;
        }
        
        /* Ensure worksheet panel is in column layout on mobile landscape */
        .worksheet-panel {
            flex-direction: column !important;
        }
    }
    
    /* Additional landscape rules for broader device coverage */
    @media (orientation: landscape) and (max-height: 600px) {
        /* Hide statistics and environment sections in worksheet panel on any landscape device */
        .worksheet-panel .stats-column,
        .worksheet-panel .environment-column {
            display: none !important;
        }
        
        /* Make worksheet section take full available space in landscape */
        .worksheet-panel .worksheet-section {
            height: calc(100vh - 80px) !important;
            max-height: none !important;
            flex: 1 !important;
        }
        
        /* Ensure worksheet panel is in column layout on landscape */
        .worksheet-panel {
            flex-direction: column !important;
        }
    }
    
    /* Specific iPhone landscape optimizations */
    @media (max-width: 896px) and (orientation: landscape) {
        .worksheet-section {
            height: calc(100vh - 100px); /* Even larger for iPhone landscape */
            padding: 12px;
        }
        
        /* Hide statistics and environment sections in worksheet panel on iPhone landscape */
        .worksheet-panel .stats-column,
        .worksheet-panel .environment-column {
            display: none !important;
        }
        
        /* Make worksheet section take full available space on iPhone landscape */
        .worksheet-panel .worksheet-section {
            height: calc(100vh - 80px) !important;
            max-height: none !important;
            flex: 1 !important;
        }
        
        /* Ensure worksheet panel is in column layout on iPhone landscape */
        .worksheet-panel {
            flex-direction: column !important;
        }
        
        /* Android specific button styles */
        .action-button {
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            transition: box-shadow 0.2s, transform 0.1s;
        }
        
        .action-button:active {
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
            transform: translateY(1px);
        }
    }
}

/* iPad landscape specific */
@media (min-width: 768px) and (orientation: landscape) {
    .panel-container {
        padding: 20px;
    }
    
    .attack-panel,
    .spells-panel,
    .items-panel,
    .worksheet-panel {
        max-width: 1200px;
        margin: 0 auto;
    }
}

/* Utility classes */
.hidden {
    display: none !important;
}

.empty {
    /* Placeholder for empty grid cells */
}

/* Add/Remove Items Dialog Styles */
.add-items-dialog .dialog-overlay,
.remove-items-dialog .dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.add-items-dialog .dialog-content,
.remove-items-dialog .dialog-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    width: 400px;
    max-height: 500px;
    display: flex;
    flex-direction: column;
}

.add-items-dialog h3,
.remove-items-dialog h3 {
    margin: 0;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    font-size: 16px;
    font-weight: 600;
}

.select-items-label,
.select-spell-label {
    padding: 12px 20px 8px;
    font-weight: 500;
    color: #333;
}

.items-selection-container {
    flex: 1;
    min-height: 0;
    padding: 0 20px;
}

.items-list-container {
    border: 1px solid #ccc;
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    background: white;
}

.item-row {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-bottom: 1px solid #eee;
}

.item-row:last-child {
    border-bottom: none;
}

.item-row:hover {
    background-color: #f5f5f5;
}

.item-row input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.item-row label {
    cursor: pointer;
    flex: 1;
    font-size: 14px;
    color: #333;
}

.dialog-buttons {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.add-items-dialog .dialog-button,
.remove-items-dialog .dialog-button {
    padding: 8px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    font-size: 14px;
    cursor: pointer;
    min-width: 70px;
    color: #333;
}

.add-items-dialog .dialog-button:not(.dialog-button-primary):hover,
.remove-items-dialog .dialog-button:not(.dialog-button-primary):hover {
    background-color: #f5f5f5;
    color: #333;
}

.add-items-dialog .dialog-content .dialog-buttons .dialog-button-primary,
.remove-items-dialog .dialog-content .dialog-buttons .dialog-button-primary {
    background-color: #007aff !important;
    color: white !important;
    border-color: #007aff !important;
}

.add-items-dialog .dialog-content .dialog-buttons .dialog-button-primary:hover,
.remove-items-dialog .dialog-content .dialog-buttons .dialog-button-primary:hover {
    background-color: #0056b3 !important;
    color: white !important;
    border-color: #0056b3 !important;
}